AppleScript Repeat For x Seconds

Discussion in 'Mac Programming' started by jcs801, Feb 19, 2013.

  1. macrumors newbie

    Joined:
    Feb 19, 2013
    #1
    I need AppleScript to repeat for a certain number of seconds. I was thinking "repeat for x seconds" but that doesn't work. Notice: This is not delay, I want the repeat to stop after x seconds.
     
  2. thread starter macrumors newbie

    Joined:
    Feb 19, 2013
    #2
    Oh, and also, a command that repeats the script until "esc" is pressed
     
  3. ytk
    macrumors regular

    Joined:
    Jul 8, 2010
    #3
    You just want it to run a loop as fast as possible for a specific duration?

    Code:
    set start_value to do shell script "ruby -e 'print Time.now.to_f'"
    repeat while true
    	-- Your code goes here
    	set end_value to do shell script "ruby -e 'print Time.now.to_f'"
    	if end_value - start_value ≥ 1 then
    		exit repeat
    	end if
    end repeat
    
    The above code will run through a loop for one second. Change the value in the if statement to adjust the amount of time. Note that you can also specify partial seconds, such as 2.5.

    Can't help you with your other problem.
     
  4. thread starter macrumors newbie

    Joined:
    Feb 19, 2013
    #4


    Where you put where my code goes, I can put anything, even delays?

    Thanks for helping!
    jcs801
     
  5. thread starter macrumors newbie

    Joined:
    Feb 19, 2013
    #5
    Woah dude, this is amazing. Thanks! I will vote up on your post.

    Btw, if you would guess my age between 10 and 30, how old would you think I am?
     

Share This Page