I want to remap § to `
and ± to ~
on my Mac keyboard because they are located in a place I am not used to.
Is there an easy way to do this?
4 Answers
Remapping § to `
and ± to ~
worked on my Mac (running OS X 10.15.6) without additional software with the following code snippet.
hidutil property --set '{"UserKeyMapping":
[{"HIDKeyboardModifierMappingSrc":0x700000035,
"HIDKeyboardModifierMappingDst":0x700000064},
{"HIDKeyboardModifierMappingSrc":0x700000064,
"HIDKeyboardModifierMappingDst":0x700000035}]
}'
To do this automatically at startup -
Create a new file named ~/Library/LaunchAgents/com.user.loginscript.plist
with the following content:
<?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>com.user.loginscript</string>
<key>ProgramArguments</key>
<array>
<string>/usr/bin/hidutil</string>
<string>property</string>
<string>--set</string>
<string>{"UserKeyMapping":[{"HIDKeyboardModifierMappingSrc":0x700000035, "HIDKeyboardModifierMappingDst":0x700000064}, {"HIDKeyboardModifierMappingSrc":0x700000064, "HIDKeyboardModifierMappingDst":0x700000035}]}</string>
</array>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
The file needs to be registered with a one-off execution of the following command:
launchctl load ~/Library/LaunchAgents/com.user.loginscript.plist
See also this solution which explains how to use Automator instead of launchctl
.

- 105
The two apps most commonly used to do this are
and
There’s a lot of other options, but these are the easiest in practice for most people to just manage their layouts easily.

- 235,889

- 20,864
-
Found it here: https://github.com/tekezo/Karabiner-Elements/blob/master/usage/README.md#how-to-configure-karabiner-elements – Mahdi Apr 20 '17 at 16:49
-
There's also the possibility that OP has selected the wrong keyboard layout on the input menu. – WGroleau Sep 30 '20 at 17:25
-
@WGroleau I've not seen any alternative input source that would do that. Perhaps you know of one? This exchange is typical of someone shifting from a US ANSI English keyboard, where `/~ is on the topmost leftmost key, to a European English ISO keyboard, where it moves to the bottom leftmost key. Or vice versa. – Tom Gewecke Sep 30 '20 at 17:59
-
Well, you just mentioned two keyboards that relocate the key OP is concerned with. – WGroleau Sep 30 '20 at 18:09
-
@WGroleau You are confusing hardware with software. ANSI and ISO are differnet kinds of hardware keyboard, not keyboard layouts, and you can't select them in the input menu. Any given keyboard layout you select in the input menu will look slightly different depending on which kind of hardware you have attached, because ISO has one key more than ANSI. – Tom Gewecke Sep 30 '20 at 20:11
-
I'm well aware of the difference. I said keyboard layout and shortened it the second time. OP is concerned with remapping, not changing hardware. Remapping is what keyboard layout files do. It may be there is no keyboard layout that puts those glyphs on that key. I haven't examine all of Apple's dozens of layouts. – WGroleau Oct 01 '20 at 01:11
Here is explains "EXACTLY" the problem that I am having with a simple solution.
You need to update karabiner.json and add this part:
{
"profiles": [
{
"name": "Default profile",
"selected": true,
"simple_modifications": {
"non_us_backslash": "grave_accent_and_tilde",
"grave_accent_and_tilde" : "non_us_backslash"
}
}
]
}

- 573
After MacOS 14.3
, hidutil
now requires admin privileges to run certain remaps and if you want to run it automatically it will not work the same way the first answer did.
To resolve this issue I had to do it this way.
Create a new script to any folder you want.
#!/bin/zsh
sudo hidutil property --set '{"UserKeyMapping":
[{"HIDKeyboardModifierMappingSrc":0x700000035,
"HIDKeyboardModifierMappingDst":0x700000064},
{"HIDKeyboardModifierMappingSrc":0x700000064,
"HIDKeyboardModifierMappingDst":0x700000035}]
}'
Create a file under
/Library/LaunchDaemons/com.yourusername.remapkeys.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>com.yourusername.remapkeys</string>
<key>RunAtLoad</key>
<true/>
<key>ProgramArguments</key>
<array>
<string>/bin/zsh</string>
<string>/path/to/your/script/com.yourusername.remapkeys.sh</string>
</array>
</dict>
</plist>
Set permissions
sudo chown root:wheel /Library/LaunchDaemons/com.yourusername.remapkeys.plist
sudo chmod 644 /Library/LaunchDaemons/com.yourusername.remapkeys.plist
Load the daemon
sudo launchctl load -w /Library/LaunchDaemons/com.yourusername.remapkeys.plist
Restart and test

- 111
-
1Don't LaunchDaemons in
/Library/LaunchDaemons
run asroot
anyway (so you can skip thesudo
/visudo
part)? – nohillside Jan 21 '24 at 10:46 -
launchctl load
- also that command returned errors Load failed: 5: Input/output error – Gal Bracha Mar 24 '22 at 10:10Also, you can use Automator to get the script to load on startup: https://www.quora.com/How-do-you-know-if-your-startup-will-be-successful/answer/Jordi-Noguer?srid=kCsL
– Francis Huang Jun 19 '22 at 20:32Where 0x343 should be replaced with the ProductID of your internal macbook keyboard. To find the correct ProductID on your macbook, click: Apple icon > About This Mac > System Report > Hardware > SPI > Apple Internal Keyboard
See also DarthRitis's answer: https://stackoverflow.com/a/58981641/56879
– Amit Moscovich Jan 02 '23 at 12:59