#!/bin/sh
## xref: https://www.reddit.com/r/MacOS/comments/jy5ry8/m1_macbook_air_keysshortcut_for_keyboard/ghryk3j/?utm_source=reddit&utm_medium=web2x&context=3
cat > ~/Library/LaunchAgents/com.local.KeyRemapping.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>com.local.KeyRemapping</string>
<key>ProgramArguments</key>
<array>
<string>/usr/bin/hidutil</string>
<string>property</string>
<string>--set</string>
<string>{"UserKeyMapping":[
{
"HIDKeyboardModifierMappingSrc": 0xC000000CF,
"HIDKeyboardModifierMappingDst": 0xFF00000009
},
{
"HIDKeyboardModifierMappingSrc": 0x10000009B,
"HIDKeyboardModifierMappingDst": 0xFF00000008
}
]}</string>
</array>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
EOF
launchctl load ~/Library/LaunchAgents/com.local.KeyRemapping.plist
Unload:
launchctl unload ~/Library/LaunchAgents/com.local.KeyRemapping.plist
rm -f ~/Library/LaunchAgents/com.local.KeyRemapping.plist
Thanks for this!
Do you know what keycodes I should use to remap the Search button + voice button instead of the Do Not Disturb button?
Edit: found it
So for example, for
https://mybyways.com/blog/script-to-re-map-macbook-pro-function-keys
0xC000000CF
= do not disturb0x10000009B
= dictation0x0C00000221
= spotlight0xFF0100000010
= mission control0x0C000002A2
= launchpadFound from here: reddit thread, HID spec hut1_22.pdf
Another source has these:
https://mybyways.com/blog/script-to-re-map-macbook-pro-function-keys