Make AppleScript delay a random number between x and y?

set DelayTime1 to {18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58}
set DelayTime2 to some item of DelayTime1
delay DelayTime2

Is there any way I can clean this up so that if I want the range to be larger I don't have to type a bunch more numbers? i.e. set DelayTime1 to 18 thru 58


Solution 1:

You can use random number, e.g.:

set timeDelay to random number from 18 to 58
delay timeDelay

Or any integer values you wish.


For more information about random number click the link. Also have a look at: AppleScript Language Guide