Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Applescript play track spotify

I want to play a track by running an applescript. I'm having trouble figuring out the play track method.

I'm doing this

tell application "Spotify"
    play track "One Thing" in context spotify:track:5Up9Lj7QWudEfMc0ve5qWW
end tell

that obviously doesn't work. I don't know what to do with the context part. What is a context?

like image 704
VarunMurali Avatar asked Aug 10 '26 19:08

VarunMurali


1 Answers

Take a look at the documentation in the AppleScript editor. Track and context are both URIs. A Spotify context is a container, and the client defaults to using the track's album.

So, for example, both of these will play the track in the context of its album (they're functionally the same):

tell application "Spotify"
     play track "spotify:track:5Up9Lj7QWudEfMc0ve5qWW"
end tell

tell application "Spotify"
     play track "spotify:track:5Up9Lj7QWudEfMc0ve5qWW" in context "spotify:album:33yaWg4n9max6UWPlD59zs"
end tell

However, you could also play a track in the context of an artist:

tell application "Spotify"
     play track "spotify:track:5Up9Lj7QWudEfMc0ve5qWW" in context "spotify:artist:2AsusXITU8P25dlRNhcAbG"
end tell

Or even a playlist!

tell application "Spotify"
    play track "spotify:track:3NN3bw0UMt3DbFUVGh78kV" in context "spotify:user:sweetlelle:playlist:6C7spm3ZSJSWL9EZAhiMFb"
end tell
like image 92
iKenndac Avatar answered Aug 12 '26 13:08

iKenndac



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!