- Go to https://hidutil-generator.netlify.app/ to create the
~/Library/LaunchAgents/com.local.KeyRemapping.plist
file.
Example:
<?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.local.KeyRemapping</string>
<key>ProgramArguments</key>
<array>
<string>/usr/bin/sudo</string>
<string>/usr/bin/hidutil</string>
<string>property</string>
<string>--set</string>
<string>{"UserKeyMapping":[
{
"HIDKeyboardModifierMappingSrc": 0x700000005,
"HIDKeyboardModifierMappingDst": 0x7000000E3
},
{
"HIDKeyboardModifierMappingSrc": 0x700000065,
"HIDKeyboardModifierMappingDst": 0x7000000E6
}
]}</string>
</array>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
-
Notice the
<string>/usr/bin/sudo</string>
? Yes, nowsudo
is needed for certain keys. To make this work automatically, need to add to the sudoers file.- Open it for editing via
sudo visudo
. - At the bottom add
<your_username> ALL = (ALL) NOPASSWD: /usr/bin/hidutil
- Open it for editing via
-
To manually load and unload the plist file:
launchctl load -w ~/Library/LaunchAgents/com.local.KeyRemapping.plist
launchctl unload ~/Library/LaunchAgents/com.local.KeyRemapping.plist
-
To manually get and set key remappings:
hidutil property --get "UserKeyMapping"
hidutil property --set '{"UserKeyMapping":[]}'
(this clears them)