6

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…

2

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.

1

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...

  1. Open System Preferences
  2. Navigate to Keyboard
  3. 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...

Screenshot of the checkbox labeled: Use F1, F2, etc. keys as standard function keys.

  • 2
    In theory it would also be possible to build an application that did what you are looking for by changing the priority of the pause/play buttons to your own app which launches when you lock the screen, but that seems overly complex. – unknowndomain Feb 19 '18 at 20:38
  • The fn-key remapping isn't a great solution as it makes it too difficult to change the volume/ play/pause etc. by humans during normal use. However, I like the idea of changing the priority of those to a custom app. To combine your two ideas, maybe I can write a script to programmatically enable the fn-necessitating behavior and then lock the screen, and I can bind it to a key combination to quickly invoke when I see the cat approaching. I'll attempt this and check back. – ijoseph Feb 20 '18 at 19:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .