How do I disable the media keys (play, pause, skip, etc.) on the macOS login window?
When playing music on iTunes or similar and then locking the screen (accomplished by hitting the ⌃⌘Q
key combination or selecting "Lock Screen" from the menu), how do I prevent the media keys from functioning?
In particular, the play, skip, and pause buttons are still functional at this point. This is problematic because I tend to lock my screen in order to prevent my cat from wreaking havoc on my laptop when she steps on the keys -- but she's still able to mess up my music via the above, usually…
Two solutions:
Solution 1: the aforementioned one to toggle the Use F1, F2, etc. keys as standard function keys
and then lock the screen via an AppleScript invoked by a system-wide hotkey:
display notification "Toggling fn keys and locking"
-- toggl fn keys
tell application "System Preferences"
reveal anchor "keyboardTab" of pane "com.apple.preference.keyboard"
end tell
tell application "System Events" to tell process "System Preferences"
click checkbox 1 of tab group 1 of window 1
end tell
quit application "System Preferences"
-- lock screen
activate application "SystemUIServer"
tell application "System Events"
tell process "SystemUIServer" to keystroke "q" using {command down, control down}
end tell
Then, the next steps are saving this as an Application, and creating a service in Automator to launch this, and setting a keyboard shortcut for that service.
However, this was too slow and also had the irritating side effect of me having to write another script to un-toggle the Use F1, F2, etc. keys as standard function keys
setting after logging back in.
Solution 2: I ended up using KeyboardCleanTool, which solves the problem more directly by locking all the keys on application startup until one clicks the relevant UI button:
KeyboardCleanTool is a super simple little tool which blocks all Keyboard and TouchBar input.
Unfortunately, this is not exactly the answer you were looking for but you can switch the keyboard media keys over so they act as function keys by default.
However this does mean you have to press the fn (function) key to use the media keys in normal use...
You can do this in System Preferences...
- Open System Preferences
- Navigate to Keyboard
- Check the option
Use F1, F2, etc. keys as standard function keys.
I would be very impressed if the cat managed to press fn + F8 to pause your music simultaneously, but cats will be cats...