Here’s a solution that does not use any external tools.
Run this in Terminal.app:
sudo hidutil property --set '{"UserKeyMapping":[{"HIDKeyboardModifierMappingSrc":0x700000035,"HIDKeyboardModifierMappingDst":0x700000064},{"HIDKeyboardModifierMappingSrc":0x700000064,"HIDKeyboardModifierMappingDst":0x700000035}]}'
Now try your ~
and ±
keys: they should be switched around.
Problem is, this fix will only work until the next restart. To make it permanent, you have to automatically run it on system load.
You can do that in three Terminal.app commands:
-
cat << 'EOF' > ~/.tilde-switch && chmod +x ~/.tilde-switch
hidutil property --set '{"UserKeyMapping":[{"HIDKeyboardModifierMappingSrc":0x700000035,"HIDKeyboardModifierMappingDst":0x700000064},{"HIDKeyboardModifierMappingSrc":0x700000064,"HIDKeyboardModifierMappingDst":0x700000035}]}'
EOF
(This is all a single command.) This stores the script from above in an invisible executable file in your home directory, ~/.tilde-switch
.
-
sudo /usr/bin/env bash -c "cat > /Library/LaunchDaemons/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
(This is all a single command.) This creates a system task: ‘run the file from step 1 on every startup.’
-
sudo launchctl load -w -- /Library/LaunchDaemons/org.custom.tilde-switch.plist
This loads (activates) the task from step 2.
Steps 2 and 3 will prompt for your password. And now, your ~
and ±
keys are permanently switched.
Note 1
This appears to work not only on the MacBook's build-in internal physical keyboard, but on the external keyboards as well.
Note 2
To undo the switching script (not the three steps), here’s the reverse script:
sudo hidutil property --set '{"UserKeyMapping":[{"HIDKeyboardModifierMappingSrc":0x700000035,"HIDKeyboardModifierMappingDst":0x700000035},{"HIDKeyboardModifierMappingSrc":0x700000064,"HIDKeyboardModifierMappingDst":0x700000064}]}'
Note 3
To undo the three steps:
sudo launchctl unload -w -- /Library/LaunchDaemons/org.custom.tilde-switch.plist; sudo rm -f -- /Library/LaunchDaemons/org.custom.tilde-switch.plist ~/.tilde-switch
Credit
This solution is inspired by this article:
http://homeowmorphism.com/2017/05/27/Remap-CapsLock-Backspace-Sierra