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
.
-
to get the hex codes of keys: apps.apple.com/tr/app/key-codes/id414568915?l=tr&mt=12 Commented Mar 22, 2022 at 17:49
-
1Is it possible to make it work only for Macbook keybaord? I have an external keybaord that the characters are correctly mapped, and switching between the keybaords can be a pain sometimes Commented May 11, 2022 at 10:40
-
3
-
2@farzadshbfn Yes, you can apply the remapping to a specific keyboard. Add the following lines inside the <array>...</array> block: <string>property</string> <string>--matching</string> <string>{"ProductID":0x343}</string> Where 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: stackoverflow.com/a/58981641/56879 Commented Jan 2, 2023 at 12:59
-
1
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.
-
Found it here: github.com/tekezo/Karabiner-Elements/blob/master/usage/…– MahdiCommented Apr 20, 2017 at 16:49
-
There's also the possibility that OP has selected the wrong keyboard layout on the input menu.– WGroleauCommented Sep 30, 2020 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. Commented Sep 30, 2020 at 17:59
-
Well, you just mentioned two keyboards that relocate the key OP is concerned with.– WGroleauCommented Sep 30, 2020 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. Commented Sep 30, 2020 at 20: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"
}
}
]
}
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
-
1Don't LaunchDaemons in
/Library/LaunchDaemons
run asroot
anyway (so you can skip thesudo
/visudo
part)?– nohillside ♦Commented Jan 21 at 10:46 -
you are correct, i was not aware of this I will update it thank you.– RaffiCommented Jan 21 at 10:57