Skip to content

Instantly share code, notes, and snippets.

@bddap
Created June 14, 2017 18:15
Show Gist options
  • Save bddap/dce09a1008c7c484035b54e1df9f0516 to your computer and use it in GitHub Desktop.
Save bddap/dce09a1008c7c484035b54e1df9f0516 to your computer and use it in GitHub Desktop.
#!/bin/bash
lctrl=30064771296
rctrl=30064771300
lcmd=30064771299
rcmd=30064771303
loption=30064771298
roption=30064771302
# -1 none
# 0 caps lock
# 1 left shift
# 2 left control
# 3 left option
# 4 left command
# 5 keypad 0
# 6 help
# 9 right shift
# 10 right control
# 11 right option
# 12 right command
# MAPPING="
# (
# {
# HIDKeyboardModifierMappingDst = $lctrl;
# HIDKeyboardModifierMappingSrc = $lcmd;
# },{
# HIDKeyboardModifierMappingDst = $roption;
# HIDKeyboardModifierMappingSrc = $rcmd;
# },{
# HIDKeyboardModifierMappingDst = $rcmd;
# HIDKeyboardModifierMappingSrc = $roption;
# }
# )
# "
#defaults -currentHost write -g "$mappingplist" "$MAPPING"
mappingplist=com.apple.keyboard.modifiermapping.1452-628-0
defaults -currentHost write -g "$mappingplist" -array "
<dict>
<key>HIDKeyboardModifierMappingDst</key><integer>$lctrl</integer>
<key>HIDKeyboardModifierMappingSrc</key><integer>$lcmd</integer>
</dict>
" "
<dict>
<key>HIDKeyboardModifierMappingDst</key><integer>$roption</integer>
<key>HIDKeyboardModifierMappingSrc</key><integer>$rcmd</integer>
</dict>
" "
<dict>
<key>HIDKeyboardModifierMappingDst</key><integer>$lcmd</integer>
<key>HIDKeyboardModifierMappingSrc</key><integer>$loption</integer>
</dict>
" "
<dict>
<key>HIDKeyboardModifierMappingDst</key><integer>$rcmd</integer>
<key>HIDKeyboardModifierMappingSrc</key><integer>$roption</integer>
</dict>
"
defaults -currentHost read -g "$mappingplist"
echo Keys set, reboot or relogin required.
# mapping command ctrl to
# (
# {
# HIDKeyboardModifierMappingDst = 30064771296;
# HIDKeyboardModifierMappingSrc = 30064771299;
# },
# {
# HIDKeyboardModifierMappingDst = 30064771300;
# HIDKeyboardModifierMappingSrc = 30064771303;
# }
# )
# mapping command to option
# (
# {
# HIDKeyboardModifierMappingDst = 30064771298;
# HIDKeyboardModifierMappingSrc = 30064771299;
# },
# {
# HIDKeyboardModifierMappingDst = 30064771302;
# HIDKeyboardModifierMappingSrc = 30064771303;
# }
# )
# https://apple.stackexchange.com/questions/4813/changing-modifier-keys-from-the-command-line/277544#277544
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment