Skip to content

Instantly share code, notes, and snippets.

@mysteriouss
Last active March 20, 2026 01:36
Show Gist options
  • Select an option

  • Save mysteriouss/7d859f4ebb20604d212e7e9f807f64ff to your computer and use it in GitHub Desktop.

Select an option

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
@pirate
Copy link
Copy Markdown

pirate commented Aug 2, 2022

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

/* AppleVendor Keyboard Page (0xff01) */
enum {
    kHIDUsage_AppleVendorKeyboard_Spotlight             = 0x0001,
    kHIDUsage_AppleVendorKeyboard_Dashboard             = 0x0002,
    kHIDUsage_AppleVendorKeyboard_Function              = 0x0003,
    kHIDUsage_AppleVendorKeyboard_Launchpad             = 0x0004,
    kHIDUsage_AppleVendorKeyboard_Reserved              = 0x000A,
    kHIDUsage_AppleVendorKeyboard_CapsLockDelayEnable   = 0x000B,
    kHIDUsage_AppleVendorKeyboard_PowerState            = 0x000C,
    kHIDUsage_AppleVendorKeyboard_Expose_All            = 0x0010,
    kHIDUsage_AppleVendorKeyboard_Expose_Desktop        = 0x0011,
    kHIDUsage_AppleVendorKeyboard_Brightness_Up         = 0x0020,
    kHIDUsage_AppleVendorKeyboard_Brightness_Down       = 0x0021,
    kHIDUsage_AppleVendorKeyboard_Language              = 0x0030,
};

So for example, for

https://mybyways.com/blog/script-to-re-map-macbook-pro-function-keys

  • 0xC000000CF = do not disturb
  • 0x10000009B = dictation
  • 0x0C00000221 = spotlight
  • 0xFF0100000010 = mission control
  • 0x0C000002A2 = launchpad

Found from here: reddit thread, HID spec hut1_22.pdf


Another source has these:

/* AppleVendor Keyboard Page (0xff01) */
enum {
    kHIDUsage_AppleVendorKeyboard_Spotlight             = 0x0001,
    kHIDUsage_AppleVendorKeyboard_Dashboard             = 0x0002,
    kHIDUsage_AppleVendorKeyboard_Function              = 0x0003,
    kHIDUsage_AppleVendorKeyboard_Launchpad             = 0x0004,
    kHIDUsage_AppleVendorKeyboard_Reserved              = 0x000A,
    kHIDUsage_AppleVendorKeyboard_CapsLockDelayEnable   = 0x000B,
    kHIDUsage_AppleVendorKeyboard_PowerState            = 0x000C,
    kHIDUsage_AppleVendorKeyboard_Expose_All            = 0x0010,
    kHIDUsage_AppleVendorKeyboard_Expose_Desktop        = 0x0011,
    kHIDUsage_AppleVendorKeyboard_Brightness_Up         = 0x0020,
    kHIDUsage_AppleVendorKeyboard_Brightness_Down       = 0x0021,
    kHIDUsage_AppleVendorKeyboard_Language              = 0x0030,
};

https://mybyways.com/blog/script-to-re-map-macbook-pro-function-keys

@mijalapenos
Copy link
Copy Markdown

Thank you so much!

@ONEKENO
Copy link
Copy Markdown

ONEKENO commented Dec 7, 2023

Thanks

@z-spondoms
Copy link
Copy Markdown

thank you very much!!!
but for spotlight its 0xC00000221 not 0x0C00000221

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