What is the default function for a play/pause media key? I have a Microsoft Natural Ergonomic Keyboard 4000.  It has a button labelled play/pause.  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.

This behaviour of remembering which app to toggle is great and I want to continue using it.  I'm now using USB Overdrive to remap the rest of the Microsoft media keys.  I am purposely not using the Microsoft keyboard driver because it conflicts with Karabiner which I also use and is compatible with USB Overdrive.

The problem is that in USB Overdrive the default is to set the play/pause button to call iTunes' play command.  This breaks the behaviour I described above.

What is the name of the default Mac play function that remembers which app to toggle?  Is there a way to run this function from Applescript or Bash?  USB Overdrive allows programming a key to launch an application.  I believe that the best solution would be to call this function from a script wrapped in a Mac application and link that to USB Overdrive.
It appears that there is a Gist on GitHub using USB Overdrive and a Windows Keyboard that addresses how to map the media keys the way you want to. Configure media keys on a non-Apple keyboard to control Spotify via AppleScript and USB Overdrive on OSX.

If you scroll down to ludalex addition to the Gist, they have added an Applescript that can identify either iTunes or Spotify and assign the Play/Pause key press to the correct app.