repeat command out of place?

Discussion in 'Mac Programming' started by thriftinkid, Jul 3, 2008.

  1. thriftinkid macrumors regular

    Joined:
    Mar 24, 2008
    #1
    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?

    Code:
    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
     
  2. lee1210 macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #2
    Code:
    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
     
  3. kalimba macrumors regular

    Joined:
    Jun 10, 2008
    #3
    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.
     
  4. thriftinkid thread starter macrumors regular

    Joined:
    Mar 24, 2008
    #4
    OK Next Step

    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:

    Code:
    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
     
  5. lee1210 macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #5
    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
     
  6. macdosth macrumors newbie

    Joined:
    Jul 26, 2009
    #6
    Closing QuickTime movie window after movie is done

    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..
     

Share This Page