CELEBRATE EARTH WEEK
Save 40% on eBooks and Web Editions*—use code EARTH now through April 27. Shop now.
Publishers of technology books, eBooks, and videos for creative people
If you're an Automator user, you probably know how to create iCal Alarm workflows, which can be set to run at scheduled times, allowing processing to occur during downtime. If you're not familiar with Automator or iCal Alarm workflows, check out some of my other tips to get acquainted...
What about AppleScripts? Can't they be run on a schedule too? You bet. There are actually a couple of primary ways this can be done.
1. Stay Opened Scripts
When you write a script in AppleScript Editor (found in /Applications/Utilities), you can save it as a stay opened application. This means that, once launched, the script remains running, and it doesn't quit automatically after processing is finished.
Saving an AppleScript as a stay opened script in AppleScript Editor
A stay opened script operates in cycles. Every so often, your script runs. Then, it waits for the next cycle, and your script runs again. To implement this functionality, you simply add an idle handler to your script as follows...
-- The idle handler runs once per cycle
-- Insert your main AppleScript code here, such as:
display dialog "Hey there!"
-- At the end of the idle handler, return the number of seconds to delay between cycles
An idle handler in a stay opened AppleScript
Copy the example above into a new AppleScript Editor document, save it as a stay opened script, and launch it. Every 10 seconds, a dialog is displayed until you manually quit the script (Command+Q). Just insert your own script code in the middle, and you're all set with a script that runs on a repeating schedule.
2. iCal Alarm Scripts
iCal can launch applications and open files. Since you can save a script as an application, this means you can tell iCal to open it. It's easy. First, save your script as an application. Next, create an iCal alarm and set it to run at the desired time and on a schedule if you wish. Last, add an Open File alarm and point it to your script application. At the scheduled time, the script launches and runs.
Scheduling an iCal even to open an AppleScript application