Repeat task at a given time?


I’m relatively new to AppleScript but I have been looking quite some time for the following:

  • the script starts the application GraphicConverter
  • it then invokes a slideshow with picture folder A
  • now the script should wait until 8 pm and then stop the slideshow
  • invoke a slideshow with picture folder B
  • wait until 8 am and stop the slideshow
  • repeat from step 2
    So far this is not a big deal. The only problem I have is “wait until 8 pm” or “wait until 8 am”. How would one achieve this under Tiger? The only way I found so far was a loop with an idle time of a 60 seconds and then check whether the given time has arrived. Are there any better possibilities?

Christoph Gartmann

Something like this in your loop?

set AM to 3600 * 8 --> 28,800 seconds after midnight; 8 AM
set PM to 3600 * 20 --> 72,000 seconds after midnight; 8 PM
if T > AM and T < PM then
	set SS to true
	set SS to false
end if

Another option is to use iCal’s ability to run a script at a given time. If you create a new calendar (maybe called “Applescript”) then make a new event for each of the times. The first would start GraphicConverter and start the slideshow. The second would stop GraphicConverter and tell it to quit.

When making the alarm, choose “run script” and then select the script you need to run.

And leave iCal running! :slight_smile:

Actually, no. iCal’s iCalAlarmScheduler app (which should be started on login, check your login items) handles making sure that alarms go off as needed. No muss, no fuss! :slight_smile:

Doh – didn’t know that! :confused:

I’ve experimented with iCal a bit, and it’s actually more useful than people might have surmised. By allowing script execution, iCal becomes a substitute for cron or anacron that’s much easier to understand and is a Mac app instead of an arcane unix-y thing. :cool: