Create a gist now

Instantly share code, notes, and snippets.

#!/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
plists=`ls ~/Library/Preferences/ByHost/.GlobalPreferences.*.plist`
/usr/libexec/PlistBuddy -c "Delete $config_key" $plists &> /dev/null
/usr/libexec/PlistBuddy -c "Add $config_key array" $plists
/usr/libexec/PlistBuddy -c "Add $config_key: dict" $plists
/usr/libexec/PlistBuddy -c "Add $config_key:0:HIDKeyboardModifierMappingSrc integer $key_right_cmd" $plists
/usr/libexec/PlistBuddy -c "Add $config_key:0:HIDKeyboardModifierMappingDst integer $key_esc" $plists
/usr/libexec/PlistBuddy -c "Add $config_key: dict" $plists
/usr/libexec/PlistBuddy -c "Add $config_key:1:HIDKeyboardModifierMappingSrc integer $key_caps_lock" $plists
/usr/libexec/PlistBuddy -c "Add $config_key:1:HIDKeyboardModifierMappingDst integer $key_ctrl" $plists
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment