ALX
ALX

Reputation: 283

In Applescript, Retrive playlist information from Spotify, and enable/disable shuffling

I know that there are many commands in AppleScript for Spotify such as the simple playpause command, but how would I pull a playlist's information from Spotify, and paste it in a choose from list? I would like it to take all of the songs from wherever you're listening from, and paste them in a choose from list so you can choose which song you would like to listen to. Is this even possible? Can I do something similar?

Also, how would you enable/disable shuffling?

Additionally, is there a way to search Spotify through AppleScript?

I'm not sure if any of these are possible, and Google doesn't have any info on this right now. Does anyone know how to do this?

Upvotes: 2

Views: 1592

Answers (1)

Ron Reuter
Ron Reuter

Reputation: 1347

The Spotify AppleScript implementation does not have specific commands to get at playlist information -- it only exposes "current track" to get info about the currently-playing track and "next track" to play the next track. You can work around this limitation to build an AppleScript array containing all the tracks in a current playlist.

set trackNameList to {}
set trackIDList to {}

tell application "Spotify"
    activate

    set shuffling to false
    set repeating to true
    set sound volume to 0

    if player state is not playing then
        playpause
    end if

    set trackID to spotify url of current track
    repeat while trackIDList does not contain trackID
        set end of trackIDList to trackID
        set end of trackNameList to name of current track
        next track
        delay 1 -- otherwise Spotify misbehaves
        set trackID to spotify url of current track
    end repeat

end tell

tell me to activate
set chosenNames to choose from list trackNameList without multiple selections allowed
set chosenName to (item 1 of chosenNames) as string

repeat with i from 1 to count of trackNameList
    set itsName to (item i of trackNameList) as string
    if itsName is chosenName then
        exit repeat
    end if
end repeat

set trackID to (item i of trackIDList) as string

tell application "Spotify"
    activate
    set sound volume to 100
    play track trackID
end tell

There is no AppleScript support for searching in Spotify.

Upvotes: 2

Related Questions