Hammerspoon is a great desktop automation tool that I use
for keyboard shortcuts, like controlling the volume on an external
keyboard (e.g., "Menu key"+F11
for Volume Down).
In macOS Catalina 10.15.7 and Hammerspoon version 0.9.81 (and likely
many other versions), you might get the following error when attempting
to bind a hotkey to F11
or keycode 103
:
ERROR: LuaSkin: hs.hotkey:enable() keycode: 103, mods: 0x0000, RegisterEventHotKey failed: -9878
ERROR: LuaSkin: This hotkey is already registered. It may be a duplicate in your Hammerspoon config, or it may be registered by macOS. See System Preferences->Keyboard->Shortcuts
In this case, F11
(keycode: 103
) is the default shortcut for “Show
Desktop”: it is not enough to disable the shortcut by unchecking it
under “System Preferences -> Keyboard -> Shortcuts”, as macOS still
reserves the hotkey.
A workaround is to bind “Show Desktop” to a key combination that you
would never likely use (like Ctrl-Cmd-Shift-Option-F11
), but it is
much preferable to delete the shortcut entirely, or set it to “none”.
The easiest way to set the hotkey combination for “Show Desktop” to “none” is to run the following script, and then reboot:
defaults write com.apple.symbolichotkeys.plist AppleSymbolicHotKeys -dict-add 36 "
<dict>
<key>enabled</key><false/>
<key>value</key><dict>
<key>type</key><string>standard</string>
<key>parameters</key>
<array>
<integer>65535</integer>
<integer>65535</integer>
<integer>0</integer>
</array>
</dict>
</dict>
"
defaults write com.apple.symbolichotkeys.plist AppleSymbolicHotKeys -dict-add 37 "
<dict>
<key>enabled</key><false/>
<key>value</key><dict>
<key>type</key><string>standard</string>
<key>parameters</key>
<array>
<integer>65535</integer>
<integer>65535</integer>
<integer>0</integer>
</array>
</dict>
</dict>
"
After rebooting, the result should be the following, highlighted in an orange box: <img src=“mac-show-desktop-none.png” width=“95%”/ >
background
The Mission Control shortcuts are stored in com.apple.symbolichotkeys
and can be read from by running defaults read com.apple.symbolichotkeys
in a terminal.
Decoding each of the shortcut values is a bit of a pain: the easiest
way for me was to enable/disable the “Show Desktop” shortcut and compare
the diffs: it seems like 36
and 37
are the entries to modify.
Finally, the entries in the array of integer parameters defines what the
hotkey for that shortcut should be: setting the parameters to (65535, 65535, 0)
seems to correspond with “none”.
I would expect this solution to be able to work for all the built-in
shortcuts, but only tested it for “Show Desktop”/F11
.
resources
A lot of information was helpful from the following:
- StackOverflow answer to “How do I change Mission Control shortcuts from the command line?”
- Defaults & symbolichotkeys in Mac OS X
- StackOverflow answer to “How to disable default Mission Control shortcuts in terminal?”
And some relevant Hammerspoon issues: