Skip to content

Instantly share code, notes, and snippets.

@mysteriouss
Last active Nov 4, 2021
Embed
What would you like to do?
M1 MacBook Air F5 & F6 KeyRemap
#!/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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment