Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
#!/bin/bash
# The easiest way to figure this out is to create a re-remapping in System Preferences ui, and then
# `defaults -currentHost read | grep com.apple.keyboard.modifiermapping`
keyboard_id="1452-632-0"
config_key="com.apple.keyboard.modifiermapping.${keyboard_id}"
# key_left_cmd=30064771299
key_right_cmd=30064771303
key_esc=30064771113
key_caps_lock=30064771129
key_ctrl=30064771296
for plist in `ls ~/Library/Preferences/ByHost/.GlobalPreferences.*.plist`; do
/usr/libexec/PlistBuddy -c "Delete $config_key" $plist &> /dev/null
/usr/libexec/PlistBuddy -c "Add $config_key array" $plist
/usr/libexec/PlistBuddy -c "Add $config_key: dict" $plist
/usr/libexec/PlistBuddy -c "Add $config_key:0:HIDKeyboardModifierMappingSrc integer $key_right_cmd" $plist
/usr/libexec/PlistBuddy -c "Add $config_key:0:HIDKeyboardModifierMappingDst integer $key_esc" $plist
/usr/libexec/PlistBuddy -c "Add $config_key: dict" $plist
/usr/libexec/PlistBuddy -c "Add $config_key:1:HIDKeyboardModifierMappingSrc integer $key_caps_lock" $plist
/usr/libexec/PlistBuddy -c "Add $config_key:1:HIDKeyboardModifierMappingDst integer $key_ctrl" $plist
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment