Stop iTunes from launching when pressing the Play/Pause button on your keyboard

October 21, 2009 · Comments

in Geek stuff

photo by lordgoroth

With the introduction of Mac OS X 10.6 (Snow Leopard) many cool features were introduced and at least one not so cool feature: whenever you press the Play/Pause button your keyboard when you have e.g. Spotify running, it opens up iTunes. Anyway, nothing we cannot solve with a little hacking, right?

First start by downloading this script and save it somewhere on your computer. (DISCLAIMER: This script was taking from this thread on Apple Discussions). The contents of the script are listed below. When the script is launched it checks if another program that uses the multimedia keys is running. If there is it ignores the request to start iTunes, otherwise it simply proceeds with starting iTunes. You can change the apps setting to list more apps that you want to prevent iTunes from launching.

#!/usr/bin/env python
import sys, os, subprocess
 
launch = True
blocker = ""
apps = ["Ecoute", "Spotify", "Songbird", "Mplayer OSX Extended", "Mplayer"]
 
ps = subprocess.Popen("/bin/ps -x", shell=True, stdout=subprocess.PIPE)
 
for line in ps.stdout.read().split("\n"):
        for app in apps:
                if app in line:
                        launch = False
                        blocker = app
 
ps.stdout.close()
 
if launch :
        os.spawnvp(os.P_WAIT, '/Applications/iTunes.app/Contents/MacOS/iTunesX', sys.argv)
else :
        print "Not launching iTunes while %s is running." % blocker

Next issue the following commands in a Terminal (of course replace <downloaded-script-location> with the directory where you downloaded the script to (e.g. /Users/myname/Downloads).

cd /Application/iTunes.app/Contents/MacOS
sudo mv iTunes iTunesX
sudo mv <downloaded-script-location>/iTunes.py iTunes
sudo chown root:admin iTunes
sudo chmod 0755 iTunes

Et voila, this should fix it. You can check by opening up Console to check the logs for the message “Not launching iTunes while is running”.

Comments, tips and suggestions welcome!

  • awesome, works like a charm!
  • kralizec
    Thank you for the script, I modified it a little.

    instead of "Ecoute", I use "Ecoute.app" so iTunes can be executed if there is the Ecoute helper running (always) that should fix the issue where people says that they can't run iTunes even without Ecoute running, because the script read "Ecoute" from the "Ecoute helper" line of the ps command
  • tom
    what i do is to leave qicktime player opened.. it catches the play/pause and does not allow itunes to start...
  • xeroOTG
    sudo chown iTunesX should be sudo chown root:admin iTunesX

    To remove,
    open a terminal,
    cd /Applications/iTunes.app/Contents/MacOS/
    sudo mv iTunesX iTunes
    close terminal
    if it still no-worky, do a permissions check

    Great script!
  • Kyle
    I've done this and now can't get iTunes to open even when Spotify etc is closed. How can I UNDO this fix?!! Please help i'm worried i've broken it!

    Thaanks
  • Hey Kyle!

    Sorry for the late reply. But if it's b0rked, just move iTunesX back to iTunes with the mv command!
  • Rob
    Hi Maarten,

    I've also used this fix, which does work (I've checked in the console), but I've decided I don't really need this behaviour now and would prefer to return things to how they were and instead I'll just set itunes to open into the store until vlc or spotify fix their own programs! I see you've said the way to undo it is move itunesX back to itunes with the mv command, could you explain in more detail exactly how I do this?

    Cheers
  • Kyle
    Hey,

    Go into Terminal, and type:

    sudo mv iTunesX iTunes

    That should rename iTunes back to normal for it to work, if not then use the second line to, I don't really know much but that's what I did to fix it :)
  • Kyle
    Oh actually you might need the line before that too, the one that starts 'cd'
  • Great hack! Too bad you actually have to use it. Thanks for posting anyway!
  • tymc
    IT WORKS !!!!

    By default, the root user is disabled on Mac OS X. If you need a root shell, you can always use : sudo tcsh
  • This gave me a problem, because songbirditunesagent was running when i quit songbird. So i changed one of the lines from
    if app in line

    to if (app in line) and not ("songbirditunesagent" in line)

    A very dirty fix, i know, but it works
  • Hello Maarten
    I'm just plain stupid. There is nothing wrong except for my reading capabilities. I tried to start iTunes from the dock with Spotify running. Your text says clearly that that is what the script stops. I saw the message in the code and when i tried to start iTunes from the terminal. I thought your script just disabled the play/paus button. Thanks for your help and a great script!
  • Hi Anders,

    Could you check in the Console what message pops up there? Or try executing /Application/iTunes.app/Contents/MacOS/iTunes in a Terminal and see if it displays any error message or such.
  • Thanks! But I have the same problem as @NCo. I can only start iTines by executing /Application/iTunes.app/Contents/MacOS/iTunes. Any ideas?
  • @NCo what's up? You should be able to launch iTunes at least by directly launching /Application/iTunes.app/Contents/MacOS/iTunesX - if that works, but the normal 'iTunes' command not, than something is not working with the script for you....
  • NCo
    Great, now I can't open iTunes at all anymore!
  • youareafaggotnco
    Blatent faggot. Learn2unix
blog comments powered by Disqus

Previous post:

Next post:

Get Adobe Flash playerPlugin by wpburn.com wordpress themes