View Full Version : repeat command out of place?
thriftinkid
Jul 3, 2008, 01:28 PM
Hey Guys,
I wrote a script that I know is close, but something is not in the right place. Basically I want the script to continously check to see if the program "musicsource_hd.osx" is still running. Once it isn't, I want my quicktime player to quit. What am I doing wrong?
tell application "System Events"
set isRunning to ((application processes whose (name is equal to "musicsource_hd.osx")) count)
end tell
repeat until isRunning is 0
if isRunning is greater than 0 then
else
tell application "QuickTime Player" to quit
end if
end repeat
lee1210
Jul 3, 2008, 01:56 PM
tell application "System Events"
set isRunning to ((application processes whose (name is equal to "musicsource_hd.osx")) count)
end tell
repeat until isRunning is 0
tell application "System Events"
set isRunning to ((application processes whose (name is equal to "musicsource_hd.osx")) count)
end tell
if isRunning is less than 1 then
tell application "QuickTime Player" to quit
end if
end repeat
I modified this so it would only enter the loop (this is off the top of my head, not at my mac) if musicsource_hd.osx is running. If it is when the script starts, it will tell quicktime to quit once that program is no longer running. Without that check it would quit quicktime whenever this script is run, even if musicsource_hd.osx was never running.
You also might want to put a delay in so the repeat loop only happens once every 5 seconds or so. Otherwise this is a very tight loop that will be constantly eating CPU time (even if what it does is not very intensive).
-Lee
kalimba
Jul 3, 2008, 01:57 PM
Hey Guys,
I wrote a script that I know is close, but something is not in the right place. Basically I want the script to continously check to see if the program "musicsource_hd.osx" is still running. Once it isn't, I want my quicktime player to quit. What am I doing wrong?
tell application "System Events"
set isRunning to ((application processes whose (name is equal to "musicsource_hd.osx")) count)
end tell
repeat until isRunning is 0
if isRunning is greater than 0 then
else
tell application "QuickTime Player" to quit
end if
end repeat
Ok, so I don't have any idea what language this is, but if it's like any of the languages I know, your problem is that you're not re-evaluating your "isRunning" variable while you're in the loop. Unless there is something about this language that will automatically cause your "isRunning" variable to change automatically, your loop will either run never or forever.
thriftinkid
Jul 3, 2008, 03:19 PM
Thanks guys. Ok here is my other issue. I am having a hard drive mount when this application is running. I want it to unmount when the application quits. It mounts fine. But when it goes to unmount, I get the following error:
Applescript Error
Finder got an error: Can't get "afp://cs:cr8ive@192.18.1.2/cs music".
Here is the script:
set sfiles to "afp://cs:cr8ive@192.18.1.2/cs music"
tell application "Finder"
activate
mount volume sfiles
end tell
delay 5
tell application "musicsource_hd.osx" to activate
tell application "System Events"
set isRunning to ((application processes whose (name is equal to "musicsource_hd.osx")) count)
end tell
repeat until isRunning is 0
tell application "System Events"
set isRunning to ((application processes whose (name is equal to "musicsource_hd.osx")) count)
delay 4
end tell
if isRunning is less than 1 then
set sfiles to "afp://cs:cr8ive@192.18.1.2/cs music"
tell application "Finder"
activate
eject sfiles
end tell
end if
end repeat
lee1210
Jul 3, 2008, 04:03 PM
I think you need to give a volume name, not the path where it was mounted. I don't know this for sure, but I would try to tell finder to eject the name of the volume that's mounted. I think it would just be "cs music".
-Lee
macdosth
Jul 26, 2009, 06:04 AM
The following script waits until a movie finishes playing in QT, and then closes the window:
tell application "QuickTime Player"
set fullmovie1 to "VIDEOCD:MPEGAV:AVSEQ01.DAT"
-- play the movie
open fullmovie1
present document 1 scale screen
-- wait until movie is done
repeat until (get done of document 1)
end repeat
-- pause for a few seconds
-- delay of greater than 2 seconds doesn't seem to work
delay 2
-- close the played movie
close document 1
end tell
If you want to quit QT instead of just closing the movie window, my guess is that "quit" or "quit when done" instead of "close document 1" above should work..
vBulletin® v3.8.6, Copyright ©2000-2012, Jelsoft Enterprises Ltd.