Apple - Use Caps Lock to switch to and from languages on Sierra

To switch keyboard layout with caps-lock key you need to remap caps-lock to F18 with command (in Terminal.app):

hidutil property --set '{"UserKeyMapping":[{"HIDKeyboardModifierMappingSrc":0x700000039,"HIDKeyboardModifierMappingDst":0x70000006D}]}'

Then, go to System Preferences/Keyboard/Shortcuts/Input Sources, use key 'caps lock' to switch input source.

No additional software is required on mac os Sierra.

To keep this working after you logout do the following: create file ~/bin/caps2f18.sh with the following content:

hidutil property --set '{"UserKeyMapping":[{"HIDKeyboardModifierMappingSrc":0x700000039,"HIDKeyboardModifierMappingDst":0x70000006D}]}' > /dev/null 2>&1

Make it executable:

chmod +x ~/bin/caps2f18.sh

Create file ~/Library/LaunchAgents/com.user.loginscript.plist with the following content:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
   <key>Label</key>
   <string>com.user.loginscript</string>
   <key>ProgramArguments</key>
   <array>
        <string>zsh</string>
        <string>-c</string>
        <string>~/bin/caps2f18.sh</string>
   </array>
   <key>RunAtLoad</key>
   <true/>
   <key>ThrottleInterval</key>
   <integer>86400</integer>
</dict>
</plist>

Execute

launchctl load ~/Library/LaunchAgents/com.user.loginscript.plist

logout login, or execute launchctl start com.user.loginscript


Although both Seil and the classic Karabiner don't work anymore under Sierra, Karabiner rewrite, "Karabiner Elements" (in a very early beta) actually works.

The UI key mapping doesn't yet work, but you can edit the config json file under ~/.karabiner.d/configuration/karabiner.json (see an example below) to map Caps Lock to F19. From there it's all the same as before - disable Caps Lock, map keyboard layout triggering to F19, profit.

Example karabiner.json:

{  "profiles": [
    {
      "name": "Default profile",
      "selected": true,
      "simple_modifications": {
        "caps_lock": "f19"
      }
    }
  ]
}

Downgrade deferred!


My tests indicate that the Caps Lock switching feature now works with Cyrillic, Greek, and Armenian keyboards in High Sierra. (These do not work in Sierra).

Tags:

Macos

Keyboard