itunes player status

i am trying to pull itunes player information into a timer program i am working on. everything that i have tested in script editor has worked perfectly, but when i move the code into apple script studio it doesn’t. for example. in this section of the code, i am trying to see what the current player state is (playing, stopped, paused). it works fine in scripted editor, but does not work in studio.

script in SE

tell application "iTunes" to player state as string
display dialog result

the result is “stopped”

in AS

tell application "iTunes" to player state as string
set the contents of text field "playerStatus" of window "main" to result
set needs display of text field "playerStatus" of window "main" to true

the result is “«constant ****kPSS»”

how can I fix this?

I think you can’t fix it. Anyway, does it matter? You can use it anyway (though a bit lengthy):

Or, in raw form:

“stopped” is an application keyword, and it has no meaning (textual meaning) out of its own context. So, at run time you see only the raw constant. It’s the same as:

I think i have found a work around for it. it mostly works, it reads the stopped and playing states fine but has a problem reading iTunes, if the player is paused. i get a connection error.

on player_status()
	tell application "System Events" to (name of processes) contains "iTunes"
	if result is true then
		using terms from application "iTunes"
			tell application "iTunes"
				if the player state is stopped then
					set theResult to "stopped"
						if current track is not missing value then set theResult to "paused"
					end try
				else if the player state is paused then
					set theResult to "paused"
					set theResult to "playing"
				end if
			end tell
		end using terms from
		set the contents of text field "playerStatus" of window "main" to theResult
		set needs display of text field "playerStatus" of window "main" to true
		return 1
	end if
end player_status

I think that the key is you need to use “get”.

I use the following to return a list of state info to a Cocoa application. -Chuck-

[This script was automatically tagged for color coded syntax by Convert Script to Markup Code]

8 years too late? :smiley: Anyway, this works in AppleScriptObjC in Xcode 4:

Tell app “iTunes”
set _playerStateRaw to {player state=playing, player state=paused, player state=stopped, player state=fast forwarding, player state=rewinding}
end tell

set _playerStateText to {“Playing”, “Paused”, “Stopped”, “Fast forwarding”, “Rewinding”}
set _playerState to “Unknown”

repeat with i from 1 to count of _playerStateRaw
if (item i of _playerStateRaw) as text = “true” then set _playerState to item i of _playerStateText
end repeat

Model: 2011 MBA
AppleScript: Xcode 4.4
Browser: Safari 537.1
Operating System: Mac OS X (10.8)