Is it possible to set up an Applescript for timed execution? I want to move some fairly substantial sized files to a server and I’d like to set the script to execute for some time in the middle of the night to avoid tying up my computer and the server during the day.
There are many apps which will launch a file x (eg., a script) when time is x (eg, iDo).
But you can set up a simple “on idle” handler and keep the script running:
global startIf
on run
set startIf to date "01/01/2003 01:03:00"
end run
on idle
if (current date) > startIf then
beep
end if
return 30 -- run this code every 30 seconds
end idle
When you save your script as an applet, check the ‘stay open’ check box in the same window. Checking the ‘stay open’ check box will cause the script to call the idle handler and to execute it and to perform task at given times. in the last example, the idel handler is called every 30 seconds and check for the date.
Using your stay open script idea, I found that if I substitute actual time in seconds and use just the time from current date I can specify an exact excution time.
global mytime
set mytime to 872800
try
with timeout of 7200 seconds - - this is to avoid a timeout error for long file transfers
end timeout
end try
on idle
copy (the time of (current date)) as string to currenttime
if currenttime > mytime then
run application "Move Archive to server2"
end if
return 10
end idle