Skip to content

Instantly share code, notes, and snippets.

@mysteriouss
Last active October 23, 2024 17:19
Show Gist options
  • Save mysteriouss/7d859f4ebb20604d212e7e9f807f64ff to your computer and use it in GitHub Desktop.
Save mysteriouss/7d859f4ebb20604d212e7e9f807f64ff to your computer and use it in GitHub Desktop.
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
@mijalapenos
Copy link

Thank you so much!

@ONEKENO
Copy link

ONEKENO commented Dec 7, 2023

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment