Skip to content

Instantly share code, notes, and snippets.

@thomasstxyz
Last active April 23, 2023 21:57
Show Gist options
  • Save thomasstxyz/1a64875ce2c57e9e3c649b6f70fc9066 to your computer and use it in GitHub Desktop.
Save thomasstxyz/1a64875ce2c57e9e3c649b6f70fc9066 to your computer and use it in GitHub Desktop.
Swap tilde ~ key with § on Mac keyboard

Swap tilde key on Mac keyboard

cat << 'EOF' > ~/.tilde-switch && chmod +x ~/.tilde-switch
hidutil property --set '{"UserKeyMapping":[{"HIDKeyboardModifierMappingSrc":0x700000035,"HIDKeyboardModifierMappingDst":0x700000064},{"HIDKeyboardModifierMappingSrc":0x700000064,"HIDKeyboardModifierMappingDst":0x700000035}]}'
EOF
~/.tilde-switch
sudo /usr/bin/env bash -c "cat > /Library/LaunchAgents/org.custom.tilde-switch.plist" << EOF
<?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>org.custom.tilde-switch</string>
    <key>Program</key>
    <string>${HOME}/.tilde-switch</string>
    <key>RunAtLoad</key>
    <true/>
    <key>KeepAlive</key>
    <false/>
  </dict>
</plist>
EOF
sudo launchctl load -w -- /Library/LaunchAgents/org.custom.tilde-switch.plist

Undo

hidutil property --set '{"UserKeyMapping":[{"HIDKeyboardModifierMappingSrc":0x700000035,"HIDKeyboardModifierMappingDst":0x700000035},{"HIDKeyboardModifierMappingSrc":0x700000064,"HIDKeyboardModifierMappingDst":0x700000064}]}'
sudo launchctl unload -w -- /Library/LaunchAgents/org.custom.tilde-switch.plist; sudo rm -f -- /Library/LaunchAgents/org.custom.tilde-switch.plist ~/.tilde-switch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment