I've found some scripts how to control Spotify through AppleScript. But they only include things like play/pause, next, previous, stop. I was searching for some references on Spotify for AppleScript, but I didn't find any.
Is it possible to add the current playing track in Spotify to a specific playlist with AppleScript, and then, assign a system wide shortcut for that script?
This actually is possible, provided you have an Internet connection.
Although the Spotify AppleScript API doesn't natively support adding songs to a playlist, you can call their Web API (which does support this feature) from your script.
It would look something like this:
do shell script "curl -i -X POST 'https://api.spotify.com/v1/users/{USER_NAME}/playlists/" & playlist_id & "/tracks?uris=" & track_id & "' -H 'Authorization: Bearer " & oauth_id & "' -H 'Accept: application/json'"
where
playlist_id
is the ID from the URL for your playlist (whether it is public or private) in the format https://open.spotify.com/user/{USER_NAME}/playlist/playlist_id
track_id
is the Spotify URI for a song (which you can get using the AppleScript API: set track_id to id of the current track
, for example)oauth_id
is the authorization key you get from OAuth when you register and authorize your application (this is the tricky one); also remember to request private playlist modification scope when you authorize if you want to be able to use this with private playlistsAs for the universal shortcut, I created a systemwide service in Automator that simply ran my AppleScript and assigned it to a shortcut in System Preferences.
1) Every single scriptable app is inherently documented. In AppleScript Editor, choose Open Dictionary… from the File menu and choose the app.
2) No, you can't modify playlists using Spotify's scripting interface.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With