I am trying to find the best way through the Spotify Applescript library to detect a track change. So far I have tried to check the position of the player - if it is 0, this is a new track, and the Growl notification appears again. (This did not work mainly if someone started the song, etc.)
I am wondering if the more plausible inactivity method of the iTunes script works and checks the name of the current track to change every couple of seconds. I'm worried it might be a bit peppy. I cannot get this code to work.
tell application "System Events"
set isRunning to ¬
(count of (every process whose name is "Growl")) > 0
(count of (every process whose name is "Spotify")) > 0
end tell
global latest_song
set latest_song to ""
on idle
tell application "Spotify"
if player state is playing then
copy name of current track to current_tracks_name
if current_tracks_name is not latest_song then
copy current_tracks_name to latest_song
set who to artist of current track
set onwhat to album of current track
tell application "Growl"
set the allNotificationsList to ¬
{"SpotifyNewTrack"}
set the enabledNotificationsList to ¬
{"SpotifyNewTrack"}
register as application ¬
"Spotify" all notifications allNotificationsList ¬
default notifications enabledNotificationsList ¬
icon of application "Spotify"
notify with name ¬
"SpotifyNewTrack" title ¬
current_tracks_name description ¬
who application name "Spotify"
end tell
end if
return 5
end if
end tell
end idle
It may be a little complicated, but any help is appreciated.
source
share