Automatically play Spotify when headphones are plugged in On my iPod I have activator to automatically open Spotify when I plug in my headphones and I would like to know if I can do a similar thing on OS X.

What I would like is to automatically play Spotify if the application is already open, otherwise, I would like Spotify to open automatically then play the music. I would also like it to stop the music when my headphones are unplugged.

Does anyone know if there is a Application that allows this to happen?
Breakaway is no longer maintained on its website, but it can still be downloaded from Sourceforge.  I've associated it with the following two AppleScripts to mute the speaker and pause Spotify when the jack is disconnected, and to play Spotify when the jack is connected.  Follow the instructions on makeuseof to see how to author AppleScript and connect it to Breakaway.

jack-disconnected.scpt

set volume output volume 0
tell application "System Events"
    set MyList to (name of every process)
end tell
if (MyList contains "Spotify") is true then
    tell application "Spotify" to pause
end if


jack-connected.scpt

tell application "System Events"
    set MyList to (name of every process)
end tell
if (MyList contains "Spotify") is true then
    tell application "Spotify"
        if player state is paused then play
    end tell
end if