I’m new to this (an hour or so). I started off with a few simple iTunes scripts which went without problem. I’ve moved on to quicktime, because the motivation for learning this in the first place is a script having to do with quicktime.
This is my script:
tell application "QuickTime Player"
if document is playing then
pause document
end if
end tell
This returns an error that it can’t get playing of the document. I also tried running JUST
tell application "QuickTime Player"
pause document
end tell
Which simply did nothing at all. I feel like I’m misunderstanding how AppleScript interacts with Quicktime.
tell application "QuickTime Player"
repeat with oneDoc in documents
tell oneDoc
if playing then
pause
-- do something else
end if
end tell
end repeat
end tell
Okay, this is my script. It does what it’s supposed to when it runs, but I’d like to save it as an application that will continue checking over and over again for the conditions. Possible?
tell application "QuickTime Player"
set mytun to true
repeat with oneDoc in documents
tell oneDoc
if playing then
set mytun to false
exit repeat
end if
end tell
end repeat
if mytun is true then
tell application "iTunes" to play
else
tell application "iTunes" to pause
end if
end tell
You can do this with an idle handler.
Then you must save the script as application with option stay open.
To check if at least one movie is currently playing can be done easier
the number in the return line specifies the recurrence of the script in seconds
on idle
tell application "QuickTime Player" to (get playing of documents) contains true
if result then
tell application "iTunes" to pause
else
tell application "iTunes" to play
end if
return 10
end idle
tell application "QuickTime Player" to (count windows) > 0
results a boolean value, not a list, so delete contains true
a “shortcut” for
set qtinfluence to false
tell application "QuickTime Player" to (count windows) > 0 contains true
if result then
set qtinfluence to true
end if
is
tell application "QuickTime Player" to set qtinfluence to (count windows) > 0
and the short version of your script:
on idle
tell application "QuickTime Player"
if (count windows) > 0 and (get playing of documents) contains true then
tell application "iTunes" to pause
else
tell application "iTunes" to play
end if
return 0.5
end tell
end idle
Note: Consider the consumption of resources while setting the recurrence interval too short
Excellent, thanks once more for your continued assistance.
The script works perfectly like this:
on idle
tell application "QuickTime Player" to set qtinfluence to (count windows) > 0
if qtinfluence is true then
tell application "QuickTime Player" to (get playing of documents) contains true
if result then
tell application "iTunes" to pause
else
tell application "iTunes" to play
end if
end if
return 0.5
end idle
When quicktime is open pausing it ahs the inverse effect on iTunes.
I’d like to add it so that when Quicktime closes all windows, it starts playing again ONCE (rather than each cycle of the program). My idea would be to use a global variable, but I can’t find any information on this for AppleScirpt