Suppress iTunes invocation on Pause/Play key

by Hunter Haugen

On my Macbook I have the F1-12 keys accessible under the Fn key, and instead by default they have various actions such as changing the volume or brightness, activating exposé, or other various functions. F7-F9 are shortcut keys for Next Track, Play/Pause, and Previous Track for music or other media.

When I got my mac I knew I didn’t want iTunes for various reasons, not the least of which is that it can’t play flac. I’m still looking for a good alternative for heavy usage of listening to my own music, but between‘s app and Pandora‘s awesome console program called pianobar (you can `port install pianobar`, I’ve only been listening to my own music about 50% of the time.

The other 50% of the time I’ve been using VLC, and it works out of the box with the keyboard media shortcuts! Except for one hitch… any time I press the Play/Pause button OS X tries to start iTunes, and there are more than one angry threads about Apple turning a deaf ear to making this configurable/disabled short of deleting iTunes. But there is a hack if you want both iTunes and VLC to co-exist.

Essentially I rename the iTunes binary and replace the original with a small script that first checks if VLC is running, and if not then launches iTunes. Just paste this into Terminal:

cd /Applications/
sudo mv iTunes iTunesX
sudo cat > iTunes << EOF
#!/usr/bin/env python
import sys, os, subprocess
launch = True
blocker = ""
apps = ["Spotify", "Songbird", "VLC"] # Add more blocking programs here
ps = subprocess.Popen("/bin/ps -x", shell=True, stdout=subprocess.PIPE)
for line in"\n"):
    for app in apps:
        if app in line:
            launch = False
            blocker = app
if launch :
    os.spawnvp(os.P_WAIT, '/Applications/', sys.argv)
else :
    print "Not launching iTunes while %s is running." % blocker
sudo chown root:admin iTunes #To match the perms of the other iTunes files
sudo chmod 775 iTunes

If you want to "reset" your iTunes, you can paste this:

cd /Applications/
sudo mv iTunesX iTunes