random delay

hey all,
very new to applescript but loving it already. I know you can use the “delay” command to make a script pause for a set amount of time. I’m wondering if there is a way to make it pause for a random amount of time (within parameters?) ie. is there a way to make it delay somewhere between 2.30 mins and 5 mins? and come up random each time? ie 2.45, 4, 3.3, ect ect?

Hi & Welcome;

Delay is in seconds so you want a random delay between 150 and 300 seconds.

set d to random number from 150 to 300 -- returns an integer
delay d

The first script above in not a good way to get your delay because your script will use more resources during the delay than if you spawn a new process with a shell script. Your script will still stop for the delay, however:

set d to random number from 150 to 300
with timeout of 360 seconds -- don't recall how long your script will wait; this makes sure it's long enough.
	do shell script "sleep " & d -- note the space after sleep.
end timeout

awesome thanks :smiley: