Control Spotify with keyboard shortcuts

Hi! I'm trying to control spotify(especially play and pause) with a keyboard shortcut. I'm unsing Apple Script, but nothing happens when i click Run Script to test it:

tell application "Spotify"
    playpause
end tell

Any ideas how to solve this problem? My main goal is to force the F8 button(play/pause) to always control Spotify.

Ok, so my solution to this problem was to create an app using Script Editor. Create a new script with this:

if application "Spotify" is running then
	tell application "Spotify" to playpause
end if

Click File and Export and select Application as the file format. I paired the launch application action for the play button in BTT and selected this application for it. The app icon will pop up when it runs on your dock, but you can actually hide that: macos - How to remove the dock icon of a shell executable? - Stack Overflow

I think you could just send a keyboard shortcut (space bar) to Spotify...

Hm... that does work. Thanks!

Related to this: After opening a specific playlist with Spotify:

    tell application "Spotify"
        play track "https://open.spotify.com/playlist/37i9dQZF1EIfUrKSfi4vkq?si=169095f7e5d64b5d"
    end tell

How do I start playing it in a robust way?

  1. It doesn't start automatically.
  2. Sendingtell application "Spotify" to play does nothing.
  3. Having BTT send the :play_or_pause_button: button does nothing. (Manually pressing it at this stage also does nothing.)
  4. Sending a space bar key to Spotify does nothing.
  5. The play menu item is greyed out, so I can't trigger that one.
  6. Sending ⇥ ⇥ ⏎ works once, but only if that play list is not already open. If I run it a second time, it will miss the play button and click the ⊕ button instad.

Anyone knows?

I ended up with this ridiculously long chain:

I solved it. Instead of using the http link to the playlist, I used the format "spotify:user:<your_username>:playlist:37i9dQZF1EIfUrKSfi4vkq", and that made it play it automatically.