4

My question is referring to the System Preferences setting that enables you to remap Caps Lock to e.g. Ctrl key.

^ Is it possible to affect this setting programmatically?

Primarily I'd be interested achieving this via defaults or some shell trick; secondarily via AppleScript (yuck).

I know I can probably achieve this by using 3rd party tools, such as KeyRemap4MacBook, but that's a last resort. But I'd rather prefer a non-3rd party solution, if possible.

My use case:

Using Keyboard Maestro and its nice macro triggers, I'm looking to automatically remap Caps Lock -> Ctrl in apps like MacVim, and toggle it back to normal Caps Lock when leaving the affected apps.

Casimir et Hippolyte
  • 88,009
  • 5
  • 94
  • 125
Henrik
  • 2,421
  • 4
  • 25
  • 33

1 Answers1

0

You can toggle this using AppleScript. It'll be a simple automation technique, that will basically do the same toggle in System Preferences for you automatically.

You can add the created AppleScript toggle to the MacVim Scripts Toolbar icon. That way, while inside the app you can toggle it, and put it off while leaving.

Is this what you're looking for ? If you still need this I'll design the AppleScript for you and post it in here in a bit.

SashaZd
  • 3,315
  • 1
  • 26
  • 48
  • That's very kind, thanks. My concern is speed; if it can be achieved in a faceless way (under the hood) without having AppleScript opening/closing windows during the operation, I'd be very interested. My admittedly lacking experience with AppleScript is that it can be quite slow compared to Unix'y hacks or switching settings via defaults. But yes, if possible to switch this setting within 500 ms or not so much longer than that, I'd be very thankful if you'd like to share an AppleScript solution. – Henrik Apr 07 '13 at 17:29