Skip to content

Instantly share code, notes, and snippets.

@qnub
Last active August 30, 2017 05:22
Show Gist options
  • Save qnub/f2708a1099060120a956a82d3999bf56 to your computer and use it in GitHub Desktop.
Save qnub/f2708a1099060120a956a82d3999bf56 to your computer and use it in GitHub Desktop.
macOS 10.12+ keyboard remap script, check https://developer.apple.com/library/content/technotes/tn2450/_index.html to add you own remap options.
#!/usr/bin/env bash
echo "This script setup switch left alt/cmd and set caps-lock to f18 on user login"
cat << 'EOF' | sudo tee /usr/local/bin/me.qnub.pc-to-mac-kb.sh
#!/usr/bin/env bash
hidutil property --set '{"UserKeyMapping":
[{"HIDKeyboardModifierMappingSrc":0x7000000e2,
"HIDKeyboardModifierMappingDst":0x7000000e3},
{"HIDKeyboardModifierMappingSrc":0x7000000e3,
"HIDKeyboardModifierMappingDst":0x7000000e2},
{"HIDKeyboardModifierMappingSrc":0x700000039,
"HIDKeyboardModifierMappingDst":0x70000006d},
{"HIDKeyboardModifierMappingSrc":0x700000082,
"HIDKeyboardModifierMappingDst":0x70000006d}]
}'
sleep 12
exit 0
EOF
sudo chmod a+x /usr/local/bin/me.qnub.pc-to-mac-kb.sh
cat << 'EOF' | sudo tee /Library/LaunchAgents/me.qnub.pc-to-mac-kb.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>me.qnub.pc-to-mac-kb</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/bin/me.qnub.pc-to-mac-kb.sh</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<false/>
</dict>
</plist>
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment