Setting a time for a script to run?

I am trying to create a script that I will eventually use as a log in item. What I would like to do is have the script do its thing only if it’s between 5:00 and 5:30 in the morning.

Is there any way do do this purely in AppleScript? If not, is there anyway to do it with a “do shell script”?

Thanks in advance,
Tom McKenna

You could definitely do this using an idle handler and “current date” to get the time. But it would probably be easier to just have something schedule the script (a la cron or iCal alerts) so you don’t have it doing nothing in the background 23.5 hours a day. I’d recommend iCal. If you’ve got it installed, chances are iCal Helper is already a startup item, and it can do what you want.

Do you mean “only do its stuff if it’s run between those times”? Just make this the first thing that the script does:

-- Quit without doing anything if outside the 05:00 - 05:30 window
tell ((current date)'s time)
  if it < 5 * hours or it > 5.5 * hours then error number -128
end tell

-- Rest of script here

Yes, that’s exactly what I meant! Your snippet works perfectly…

The script that I am writing is sort of a morning log-in script. It opens the websites I read every morning (in tabs!), gets the mail, lowers the volume on my machine, launches iTunes and plays a list of (somewhat) soft music, etc.

It’s really a neat little script…

Anyway, thanks for the help!

–Tom McKenna