Been searching the BBS system for this, but cannot find it.
Anybody know of a way to have a script that waits until a date or day of month to trigger? And then goes “dormant” until it sees another day of the next month to trigger again?
Been searching the BBS system for this, but cannot find it.
Anybody know of a way to have a script that waits until a date or day of month to trigger? And then goes “dormant” until it sees another day of the next month to trigger again?
You can do this via an idle handler.
Use a property to store the last time the script was run (so that it’s persistant through quits/reboots/etc.), then check periodically (once per day?) to check the date and see if it’s time to run again.
property dayToRun: 1 -- run on the 1st of the month
property lastRun: "July" -- when did we last run? Used to prevent running twice in a month
on doStuff ()
-- whatever it is you want to do here
end doStuff
on idle
if (day of (current date) is dayToRun) and (month of (current date) is not lastRun)
doStuff()
set lastRun to month of (current date) -- and record when we last ran
end if
return 1 * days -- come back and check again tomorrow
end idle
A slightly neater idle handler would pre-calculate how long until the next iteration and return that, rather than checking once per day), but that’s left for you
A couple questions about this:
If the computer is restarted or shutdown, aren’t the properties lost? If not, where are they stored?
Would this be a startup item to trigger the script? Or does the mac clock somehow tirgger it? How does the “idle” handler work?
On the properties question, no, they are not lost.
The whole point of properties is that they are persistent. When the script quits (assuming it quits normally and not because of a crash or power outage), AppleScript saves the current script properties inside the script so they are restored when you reopen the script.
The script merely defines the default value for the property that is used whenever the script is recompiled.
As for using the script, you should save it as an Application with the ‘Stay open’ option selected. This makes the script stay open, and the idle handler is called periodically so your script can do additional processing.
Once saved, you can add it to the Login Items so that it’s launched automatically when you log in.
Has anyone tried using iCal for launching an AppleScript on a certain date? See Apple’s iCal web page…
Yup, I tried it right after they put the how-to on the site. It works as advertised but if someone needs the function of the Mail action script that must modified, it isn’t an ideal solution.
– Rob
I just tried it too. It does launch the AppleScript, but iCal will have to be running 24/7. So I agree that it’s not an ideal solution, but it’s kinda nifty ;¬)
My experience indicates that iCal does not have to be running to execute scheduled events. There must be a daemon that takes care of it.
– Rob
Looking for a way to trigger script via calendar in Entourage. Know of a way?
Thanks.