Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Feb 19, 2013, 05:58 PM   #1
jcs801
macrumors newbie
 
Join Date: Feb 2013
AppleScript Repeat For x Seconds

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.
jcs801 is offline   0 Reply With Quote
Old Feb 19, 2013, 06:16 PM   #2
jcs801
Thread Starter
macrumors newbie
 
Join Date: Feb 2013
Oh, and also, a command that repeats the script until "esc" is pressed
jcs801 is offline   0 Reply With Quote
Old Feb 19, 2013, 08:54 PM   #3
ytk
macrumors regular
 
Join Date: Jul 2010
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.
ytk is offline   1 Reply With Quote
Old Feb 19, 2013, 09:06 PM   #4
jcs801
Thread Starter
macrumors newbie
 
Join Date: Feb 2013
Quote:
Originally Posted by ytk View Post
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.


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

Thanks for helping!
jcs801
jcs801 is offline   0 Reply With Quote
Old Feb 19, 2013, 10:13 PM   #5
jcs801
Thread Starter
macrumors newbie
 
Join Date: Feb 2013
Quote:
Originally Posted by ytk View Post
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.
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?
jcs801 is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 03:29 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC