13.18. Scheduling Scripts to Run with the cron
In Chapter 3, I showed you how to schedule your salutation application to run every time you log in to the system. You can also schedule programs to run at particular times, such as on the first of every month, every morning at 6 AM, or every 10 minutes. You do this with a feature of OS X known as cron.
The cron process is always running in the background on your computer. The process checks for scheduled events and, when necessary, initiates their execution. An event is scheduled for execution through a text file known as the crontab. There is a system crontab (stored in /etc/crontab), where the administrator can specify system programs to run on a periodic basis. A program scheduled this way might clean up temporary files or backup files, for example.
You can also have your own crontab and store it where you like. The next Try It Out shows you how to schedule a program to run once an hour and to sound a chime like a big clock. It's called Big Ben!
13.18.1.
13.18.1.1. Try It Out: Chime the Hour!
In this program, you make your program chime every hour.
Type the following program into Script Editor:
-- Big Ben! -- Get the hour set theTime to time string of (current date) set theHour to first word of theTime as integer -- adjust for a 24-hour clock if theHour is 0 then set theHour to 12 else if theHour is greater than 12 then set theHour to theHour - 12 end if -- Ring the hour repeat theHour times say "ding" using "Bells" end repeat ...
Get Beginning AppleScript® now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.