I have three solutions, two helpful, one not.
The helpful:
Try polling every few seconds instead of every half second. That way the application can still quit.
Create a 'shutdown Spotify' script that quits the first script, then tells Spotify to quit.
The unhelpful:
Throw them $5/month for Spotify Unlimited and the ads go away.
Post the code of your script. I get an error eg error "This script contains uncompiled changes and cannot be run." when trying to open it. I'm running Snow Leopard. The Read My Scripts utility found at this link http://www.macosxautomation.com/applescript/apps/readmyscripts.html says it's Not an uncompiled script.
repeat #Repeat forever
try #Try to do this thing, and on error... (look at "on error" at the bottom)
tell application "Spotify"
#Setting variables
set cur_vol to sound volume
set trackk to track number of current track
set namme to name of current track
set pop to popularity of current track
set dur to duration of current track
set pos to player position
end tell
if pop is 0 and dur is less than 40 then #If popularity is 0 and duration of current track is less then 40
tell application "Spotify" #Do our thing
pause
set sound volume to 0
play
end tell
delay dur - pos + 1 #When an ad ends,
tell application "Spotify"
set sound volume to cur_vol #restore the volume to the level it was before
end tell
else
delay 0.5 #If nothing worked (it must be a music track, not an ad), try and run this script again in 0.5 seconds.
end if
on error errorMessage #On any error
delay 0.5 #Run this script again in 0.5 seconds
end try
end repeat
repeat
tell application "System Events"
set isRunning to (count of (every process whose bundle identifier is "com.spotify.client")) > 0
end tell
if isRunning then
-- do your stuff with Spotify
else
exit repeat
end if
end repeat
Try this :
Code:repeat tell application "System Events" set isRunning to (count of (every process whose bundle identifier is "com.spotify.client")) > 0 end tell if isRunning then -- do your stuff with Spotify else exit repeat end if end repeat
Try this :
Code:repeat tell application "System Events" set isRunning to (count of (every process whose bundle identifier is "com.spotify.client")) > 0 end tell if isRunning then -- do your stuff with Spotify else exit repeat end if end repeat
Code:tell application "Spotify" to set playerState to player state
Tip :Take a look at the Spotify dictionary in scripteditor to see
how to use it with Applescript.