There is only one truth. It is the source.

Make Microsoft play/pause media button work the way I want in USB Overdrive

August 2, 2015

Tags: karabiner, keyboard

UPDATE (2015-08-03): A better solution to this problem: remove the play button item from USB Overdrive and it won't overwrite the behaviour

Use USB Overdrive to program the play/pause button of a Microsoft keyboard via Applescript:

on is_running(appName)
    tell application "System Events" to (name of processes) contains appName
end is_running

if is_running("iTunes") then
    tell application "iTunes"
        playpause
    end tell
else
    tell application "Spotify"
        playpause
    end tell
end if

This roughly emulates the default behaviour of the play/pause button because I don't know how to link USB Overdrive to this original function.

When I have no keyboard drivers installed, the way the button behaves is by toggling playing and pausing in whatever most recent application that supports the behaviour. For example, if my browser is the currently focussed app, but the previously focussed app is iTunes, then the button will play and pause the sound in iTunes. If the previous app was Spotify, the button will trigger in Spotify. The same goes for VLC.

I need to use USB Overdrive to program the media keys because the Microsoft keyboard driver is not compatible with Karabiner. Unfortunately turning on USB Overdrive means that the default behaviour of the play/pause button is replaced.