Spotify always starts and I’d like it not to on my Mac

Have you tried disabling it from the startup login? If not try this.

  • Click on the Apple menu > System Preferences > System > Uses & Groups. Click on Login Items.
  • The list of apps which are automatically launched when you login, will be displayed in this section.
  • Uncheck the items you don't really need.

Option-Click on the icon in Finder to bring up the Force Quit option, and click that.

Otherwise, you can easily do this from the command line via Terminal with the following command:

ps aux | grep -i spotify | awk '{print $2}' | xargs kill -9

or

kill -9 $(ps aux | grep -i spotify | awk '{print $2}')

I'm not on my Mac right now, so it may actually be awk '{print $1}', but I believe for the OS X output, the second column will give you the PID you are looking for.

A little more than you asked for:

If you try to kill or kill -9 a non-existent PID, kill will vomit some confusing "help" output to STDERR. If you want to avoid this output when this command fails (which won't hurt anything), just redirect STDERR to /dev/null, which would make the above commands as follows:

ps aux | grep -i [s]potify | awk '{print $2}' | xargs kill -9 2>/dev/null

or

kill -9 $(ps aux | grep -i [s]potify | awk '{print $2}') 2>/dev/null

I actually have an extremely handy function in one of my dotfiles, which gets sourced in my .bash_profile during every terminal session, which is as follows (please excuse the language -- but this is really what I call it):

fuckyou() { ps aux | grep -i "$1" | grep -v 'grep' | awk '{print $2}' | xargs kill -9 2>/dev/null; }

For me, this creates the fuckyou command, which takes one argument (the name of whatever offending process I wish to terminate), finds the process ID (PID) of that process and terminates it.

This way, if you were me, you could simply run fuckyou spotify.

The one caveat is if there are multiple processes running with the same same, such as Spotify.app and com.spotifyhelper.plist or something, you would either need to explicity specify "Spotify.app", but grep -i is case insensitive, so you could say fuckyou 'Spotify.app'.

If you wanted to kill all processes under a certain name (as in all processes associated with Spotify), you would need to put the one-liner in a for or while loop, such as this:

for i in $(ps aux | grep -i [s]potify | awk '{print $2}'); do kill -9 "$i" 2>/dev/null; done

This is basically telling Bash to do the follwoing:

  • Print all running process names along with their process IDs (ps aux)
  • Do a case-insensitive search for "spotify" on this output (the bracketed first character will prevent returning the grep -i spotify process)
  • Grab only the second column of process IDs (which should now only include processes related to Spotify)
  • For all of these Spotify-related processes, force each one to terminate