Skip to content

Instantly share code, notes, and snippets.

@Austinate
Forked from zats/REMAP_M1_KEYS.MD
Created January 4, 2023 12:06
Show Gist options
  • Save Austinate/9c8bd932e06386cea88ff0ce6b5b3053 to your computer and use it in GitHub Desktop.
Save Austinate/9c8bd932e06386cea88ff0ce6b5b3053 to your computer and use it in GitHub Desktop.
Apple M1 MacBook Do Not Disturb Key remapping

Following is a sample of LaungAgent that remaps do not disturb key to Siri (I am using Type to Siri)

This is a lightweight solution not relying on external apps.

Setting up

  1. Create ~/Library/LaunchAgents/com.local.KeyRemapping.plist
  2. Edit it to have following content
<?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": 0xC00000221,
              "HIDKeyboardModifierMappingDst": 0x700000068
            },
            {
              "HIDKeyboardModifierMappingSrc": 0x10000009B,
              "HIDKeyboardModifierMappingDst": 0x700000069
            }
        ]}</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
</dict>
</plist>

This configuration will be loaded automatically every time macOS restarts, see Test Changes section if you want to experiment with alternative mappings

  • Example above remaps
    • Spotlight Key (πŸ”) to F13
    • DND key (πŸŒ™) to F14
  • If you are using Raycast
    • Under Preferences β†’ Raycast HotKey press Spotlight Key (F4 / πŸ”), you should see
  • Remap Siri
    • Navigate to System Preferences β†’ Siri β†’ Keyboard Shortcut β†’ Custom
    • Press DND key (F6 / πŸŒ™) - you should see F14 mapped as a shortcut
    • Optionally enable "Type to Siri" under System Preferences β†’ Accessibility

Notes

To remap multiple keys, add more elements under "UserKeyMapping"

To find hex values, follow documentation and section 10 of the HID USB tables (search for "Keyboard/Keypad Page (0x07)")

TLDR: value = 0x700000000 | key_code

Testing changes

  • Loading: launchctl load -w ~/Library/LaunchAgents/com.local.KeyRemapping.plist
  • Unloading: launchctl unload ~/Library/LaunchAgents/com.local.KeyRemapping.plist
  • Printing currently active mappings hidutil property --get "UserKeyMapping"

Permanently removing

launchctl unload ~/Library/LaunchAgents/com.local.KeyRemapping.plist
rm ~/Library/LaunchAgents/com.local.KeyRemapping.plist
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment