28

On macOS, if I hit the play button on the keyboard after closing all apps, iTunes starts. (If Spotify is open then it will play music instead.)

I don't use iTunes. Is it possible to make Spotify open when I hit the play button?

I have found this answer, but the top answer there refers to an old version of Karabiner and no longer works. The other answers don't achieve what I'm looking for: I'd like Spotify to open if I press play and Spotify is closed, and otherwise I'd like the play button to behave as normal, where it can play/pause any supported media application e.g., YouTube and VLC.

microbug
  • 463
  • 1
  • 5
  • 9
  • Might help if you list what Mac and keyboard you're using. None of my Macs (all desktops with Apple keyboards) have a Play button. – jimtut Mar 07 '18 at 01:59
  • @jimtut It's my MacBook Pro connected to an Apple Magic Keyboard. My MacBook Pro has a touch bar but I'm interested in this mostly when it's connected to an external display and shut (so I can't use the touch bar in that situation). – microbug Mar 08 '18 at 16:07
  • Have you found any solution in the meantime? I wonder if a more complex apple script could achieve both, launch and play Spotify if not open and then otherwise maintain the play/pause of last active media app (i.e. between YouTube, Spotify, VLC etc.) – Markus Jan 27 '23 at 10:38

3 Answers3

5

Finally got to try this on a Mac with that kind of keyboard (iMac). For me, the Play/Pause key plays whatever app (iTunes or Spotify) was last playing. If neither are opened, neither will launch, so the key doesn't default to iTunes for me.

I installed Karabiner, as linked in the question. I couldn't see how to create the steps shown in that link, but if you want to get into customizing that app, I'm sure it would work. Looks pretty powerful.

But, this gets you pretty close?.. I followed the top-rated answer at https://apple.stackexchange.com/questions/175215/how-do-i-assign-a-keyboard-shortcut-to-an-applescript-i-wrote and created an Automator app running a simple Applescript:

tell application "Spotify"
    activate
    playpause
end tell

I couldn't get my Mac to run the Automator service through a keyboard shortcut. So, instead, I fell back to my favorite free third-party keyboard/shortcut tool, QUicksilver. There's a ton more like that, though, so take your pick.

It was pretty easy to bind a shortcut key to the AppleScript itself (didn't need the Automator Service for this), except it wouldn't let me pick the "real" Play/Pause key, only F8 (press Fn key and press F8/PlayPause key).

But, with this AppleScript, pressing F8 does launch and play/pause Spotify! If Spotify was closed, it will launch, but it will "miss" the play command. So just press F8 again.

Feel free to tweak the AppleScript to be more aware of it Spotify is running or not. Shouldn't be too hard to do, but then again, it's not too hard to press F8 twice if it wasn't running either...

jimtut
  • 1,608
  • 2
  • 11
  • 17
  • It's not perfect but it's the best solution I've seen so far, thanks – microbug Jun 19 '19 at 15:12
  • This works, however I personally prefer not to have the `activate` line to prevent Spotify opening up. – Envil Sep 30 '19 at 11:10
  • This does not maintain the play/pause function of the last opened media app i.e. YouTube, Spotify etc. which is what the OP was asking for and a great feature in general - if we only could set the default app to be Spotify to launch and play. =) Maybe the apple script could be enhanced to only launch spotify and play if not already opened, and otherwise use the last active media app to play/pause, that would be awesome. – Markus Jan 27 '23 at 10:35
4

noTunes does exactly what is asked: https://github.com/tombonez/noTunes

Specifically this part: https://github.com/tombonez/noTunes#set-replacement-for-itunes--apple-music

I press play, Spotify opens. If Spotify is already open, play/pause works as normal.

  • Works great ! This is the simplest solution I've found. – CCH Apr 19 '23 at 15:31
  • 1
    Thanks! Installed this and it's nice solution to the problem. The only minor glitch is that when I press Play-button (F8) after Spotify is open it doesn't start the playback of music. I need to start playback by clicking with the mouse in the Spotify app. After that the Play-button is assigned to Spotify and starts and stops music as it should. – Vesa Jun 18 '23 at 12:54
  • No good for me. It doesn't launch (nor play) Spotify for me. Only quickly hides iTunes app after it's opened on Play button click. – Alex Aug 17 '23 at 12:41
2

You can install Better Touch Tool and set that configuration as below. Works perfect. Easiest way to achieve that requirement.

Set spotify as default player using better touch tool

  • 1
    This prohibits the play/pause button from working as usual if media is playing though – mrossman Jul 12 '22 at 14:39
  • +1 exactly, same as the other answer for using the suggested apple script via automator. Pitty as this behaviour to continue play/pause the last media app is quite useful, when switching between YouTube and Spotify... – Markus Jan 27 '23 at 10:36