Skip to content

Instantly share code, notes, and snippets.

@apfelchips
Last active June 23, 2025 21:35
Show Gist options
  • Save apfelchips/da1eed8d74aabd8caee9ce2968de6ed9 to your computer and use it in GitHub Desktop.
Save apfelchips/da1eed8d74aabd8caee9ce2968de6ed9 to your computer and use it in GitHub Desktop.
macOS US layout fix tick location on ISO Keyboards + Capslock --> LCtrl
#!/usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'
if [ "$(id -u)" -ne 0 ]; then
echo "Script has to be run as root"
exit 1
fi
KEYMAP=$(cat << EOF | tr -d ' ' | grep -v '^#' | tr -d '\n'
# https://apple.stackexchange.com/a/374074
# https://developer.apple.com/library/archive/technotes/tn2450/_index.html
{"UserKeyMapping":[
{
# Caps Lock --> Left Control
"HIDKeyboardModifierMappingSrc":0x700000039,
"HIDKeyboardModifierMappingDst":0x7000000E0
},
{
# Grave Accent and Tilde --> Non-US \ and |
"HIDKeyboardModifierMappingSrc":0x700000035,
"HIDKeyboardModifierMappingDst":0x700000064
},
{
# Non-US \ and | --> Grave Accent and Tilde
"HIDKeyboardModifierMappingSrc":0x700000064,
"HIDKeyboardModifierMappingDst":0x700000035
}
]}
EOF
)
set -x
hidutil property --set $KEYMAP >/dev/null
hidutil property --get "UserKeyMapping"
<?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>Disabled</key>
<false/>
<key>EnvironmentVariables</key>
<dict>
<key>__Comment</key>
<key>__Install_Location</key>
<string>/Library/LaunchDaemons/ / owner: root group: wheel</string>
</dict>
<key>Label</key>
<string>me.user.keyremaps</string>
<key>Program</key>
<string>/Library/LaunchDaemons/keyremap.sh</string>
<key>RunAtLoad</key>
<true/>
<key>StartInterval</key>
<integer>600</integer>
</dict>
</plist>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment