controlling quicktime with Applescript
Hardly any experience with AppleScript; I got my knowledge from various forums.It may be a simple script, but at least it works!
I tried to make an AppleScript to play just one song in a Filemaker Pro environment; everything else is handled by FMP; it only needs to know whether to stop or move to the next song.
You can guess the meaning of the few Dutch words.
###############################################################
set url_path to cell "bestandspad" of current record
tell application "QuickTime Player"
activate
open URL url_path
play document 1
end tell
tell application "System Events"
set visible of process "QuickTime Player" to false
end tell
Set tekst to ""
set the clipboard to tekst
--repeat while song is playing
--repeat with loopvariable from startvalue to stopvalue --- definition in AppleScript Language Guide
--set loopvariable to 0
--repeat with loopvariable from 0 to duration of document 1
-- 'current time' and 'duration' are properties of document 1 according to library AppleScript Editor
repeat
display dialog "Interrupt" with title "" buttons {"Stop", "Pauze", "Next song"}
if button returned of result is "Stop" then
set tekst to "Stop"
exit repeat
else if button returned of result is "Next song" then
set tekst to "Next song"
exit repeat
else
tell application "QuickTime Player" to pause document 1
display dialog "Verder gaan ?" with title "" buttons {"Stop", "Hervat"} default button 2
if button returned of result is "Hervat" then
tell application "QuickTime Player" to play document 1
--resume doesn't work here, play does.
else
set tekst to "Stop"
exit repeat
end if
end if
--set loopvariable to current time of document 1
end repeat
tell application "QuickTime Player" to quit
set the clipboard to tekst
-- can this script return a value (to FMP) ?
###################################################################
The program works fine mostly, but for two things.
First of all, the line 'tell QTP to resume" doesn't respond; pause works fine, but the playing is not resumed. It does work however with 'to play', strange.
Secondly, I make use of the clipboard for transferring data between programs (in this case from the Applescript back to FMP), but it must be possible for the Applescript to return a value to FMP in a less childish way; I haven't found that way.
Is it possible to set the position of the dialog screens?
Lastly, I found the "repeat with"-command in the AppleScript Language Guide, but I can't figure out how it exactly works. I want the repeat loop to last while the song is being played.
According to the dictionary in the AppleScript editor the properties 'current time' and 'duration' must be available for each document.
Most probably I am messing up with adressing the properties; the concept is not very clear to me.
This script does not include 'repeat with', but I have indicated in the comment lines what I have tried out, be it without success.
I still wonder what'll happen if no button is touched during the song's playing. Does QTP give a signal, when the song's playing has ended? Can I use the property 'Playing' to that purpose?
Any other suggestions to make the script simpler and/or more efficient are also welcome.
iMac 3.06, Mac OS X (10.6.3)