Finding player state in QuickTime

Howdy all, I read the sticky for noobs (although the description link took me to a 404 page) and am hoping to get a little guidance.

I am VERY new at scripting so bear with me. I would like to write a script that detects if it is iTunes or QuickTime that is currently playing, pause it that app and also set it as “lastPaused”. Later with another script I would like to have it resume whichever app was set as lastPaused.

I got the iTunes portion working:

set iTunesState to ""
property lastPaused : ""

tell application "iTunes" to set iTunesState to (player state as text)

tell application "iTunes" to get player state
if iTunesState is equal to "playing" then
	tell application "iTunes" to playpause
	set lastPaused to "iTunes"
else if ((iTunesState is equal to "paused") and (lastPaused is equal to "iTunes")) then
	tell application "iTunes" to playpause
end if

I am sure there is probably a more elegant/simple way of doing it, but this seems to work. HOWEVER, I can’t make it do the same for QuickTime. Here is what I have for it:

set QuickTimeState to ""
property lastPaused : ""

tell application "QuickTime Player" to set QuickTimeState to (QuickTimeState as text)

if QuickTimeState is equal to "playing" then
	tell application "QuickTime Player" to pause v
	set lastPaused to "QuickTimePlayer"
else if QuickTimeState is equal to "paused" then
	tell application "QuickTime Player" to resume v
	set lastPaused to "QuickTimePlayer"
end if

I have no idea why it doesn’t work…does it take different commands? Different definitions? I looked through the built in dictionary in Apple Scriptor but couldn’t find anything that showed me how to get the state for QT.

I’m working on them separately and would like to combine them once it all works for use in a Keyboard Maestro macro that I use for work. Please help! Any ideas are greatly appreciated. And if I broke some forum rule I apologize in advance haha. :stuck_out_tongue:

-Chris

– Something like:


tell application "QuickTime Player"
	tell document 1
		set playState to playing
		
		if playState then
			pause
		else
			play
		end if
		
	end tell
end tell

Hi. Welcome to MacScripter.

Thanks for pointing this out. I’ve passed it up the line. :slight_smile:

I hope you can understand kerflooey’s reply. The value of a QuickTime Player document’s playing property is a ‘boolean’ (ie. either true or false) which you can used directly after if in an if statement.

The equivalent property in iTunes is player state. It can have one of three values which are tokens unique to iTunes: stopped, paused, or playing. These are scripting keywords in iTunes, not text, so you’d write playing, not “playing”. Something like this:

set iTunesState to ""
property lastPaused : ""

tell application "iTunes"
	set iTunesState to player state
	if (iTunesState is equal to playing then)
		playpause
		set lastPaused to "iTunes"
	else if ((iTunesState is equal to paused) and (lastPaused is equal to "iTunes")) then
		playpause
	end if
end tell