player state as text stopped working?

Hey group

Couldn’t find exactly what I need when I searched, but here’s the issue:

The code is for an Alfred Workflow that stopped working recently. For some reason the code won’t compile now.

I get a

error when I try to compile it. It’s worked fine for months. Any ideas would be helpful. I’ve found some (at least) tangential info here, but not a pure answer.http://macscripter.net/viewtopic.php?id=33478

The script should find the last used player (iTunes or Spotify) and change its state (play/pause)


property lastActiveApp : ""

on send_command(player, command)
	run script "tell application \"" & player & "\" to " & command
	set lastActiveApp to player
end send_command

on alfred_script(q)
	set itunesState to ""
	if application "iTunes" is running then
		tell application "iTunes" to set itunesState to (player state as text)
	end if
	set spotifyState to ""
	if application "Spotify" is running then
		tell application "Spotify" to set spotifyState to (player state as text)
	end if
	tell application "System Events"
		set frontmostApp to item 1 of (get name of processes whose frontmost is true)
	end tell
	
	if itunesState is equal to "playing" then
		send_command("iTunes", q)
	else if spotifyState is equal to "playing" then
		send_command("Spotify", q)
	else if frontmostApp is equal to "iTunes" or frontmostApp is equal to "Spotify" then
		send_command(frontmostApp, q)
	else if lastActiveApp is equal to "iTunes" then
		send_command("iTunes", q)
	else if lastActiveApp is equal to "Spotify" then
		send_command("Spotify", q)
	end if
	
	if (lastActiveApp is not equal to "" and q is equal to "playpause") then
		set currentState to (run script "tell application \"" & lastActiveApp & "\" to return (player state as text)")
		if currentState is equal to "playing" then
			set currentState to "â–¶"
		else
			set currentState to "❚❚"
		end if
		return currentState & "  " & lastActiveApp
	end if
	
end alfred_script

Hi. I have neither Spotify nor Alfred, so perhaps I’m overlooking a nuance, but why are you coercing the constant to text? Both apps understand the player state term. Since playpause is already a toggle, I also don’t see the neccessity of even obtaining the state. As long as both apps are running and aren’t already playing simultaneously, one should be stopped and the other started.

tell application "iTunes" to playpause
tell application "Spotify" to playpause

I didn’t really look into Alfred, but maybe with Yosemite something has changed. I’ve noticed that Alfred has been updated yet.