Skip to content

Instantly share code, notes, and snippets.

@callemo
Last active October 13, 2019 06:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save callemo/9b43c54298b4565dd2521cc7b6258717 to your computer and use it in GitHub Desktop.
Save callemo/9b43c54298b4565dd2521cc7b6258717 to your computer and use it in GitHub Desktop.
Remapping Keys in macOS
#!/bin/bash
# Remapping Keys in macOS
# https://developer.apple.com/library/archive/technotes/tn2450/_index.html
set -e
userscript="$HOME/bin/userkeymap"
mkdir -p "$HOME"/bin
cat <<EOF > "$userscript"
#!/bin/bash
hidutil property --set '{"UserKeyMapping": [
{"HIDKeyboardModifierMappingSrc": 0x700000064, "HIDKeyboardModifierMappingDst": 0x700000035}
]}'
EOF
mkdir -p "$HOME/Library/LaunchAgents"
cat<<EOF >"$HOME/Library/LaunchAgents/userkeymap.plist"
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>userkeymap</string>
<key>ProgramArguments</key>
<array>
<string>$userscript</string>
</array>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
EOF
chmod +x "$userscript"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment