One of the little-known features of iCal is the ability to schedule future alarms along with an AppleScript action. AppleScript is Apple’s consumer-based programming language that allows you to write simple scripts that will automate repetitive tasks on your Mac. AppleScript lets you do simple things from opening applications and favorite websites to more advance tasks that can even change the behavior of your Mac.
In this article, however, we’ll show you how to set up iCal AppleScript alarms by tackling the morning routine of starting up applications on your computer. First, we’ll write a simple AppleScript that launches the applications you use. Next, we’ll set an iCal alarm to fire at the time we arrive to work. This alarm will be linked to the AppleScript we create so that all of the applications we’ll need to use will automatically be launched for us, and ready for us to use and begin our day.
Let’s get started.
1. Create the AppleScript Launcher
The first step is to open the AppleScript Editor (located in /Applications/Utilities). This text-based editor is where we will type our script that will automatically launch our favorite applications when it is run. After opening the AppleScript Editor, type in the following line of code:
tell application "Safari" to launch
The code is read just like an English sentence. This line of code will launch the Safari web browser. You can substitute Safari for the name of any other application that is on your Mac — just ensure that you type the application name in double-quotes just as it appears in the Finder. You will repeat this line of code on new lines, replacing the application names that you would like to launch.
So, since we need to launch Safari, Firefox, and Mail, we would type the follow lines of code into the AppleScript Editor:
tell application "Safari" to launch
tell application "Firefox" to launch
tell application "Mail" to launch
You can test your script at any time by clicking the “Run” button in the toolbar of the editor.
Then, when the script is run, it will launch Safari first, followed by Firefox and Mail. This is because the AppleScript will be run sequentially, line-by-line.
After you have typed in the script, we’ll move on to saving the script file and adding it to an iCal alarm.
2. Save the AppleScript
When saving, pick a save location that you will remember in the future.
To save the AppleScript, go to File > Save. In the resulting save dialog, type in a meaningful name and select a location to save your file. Before clicking the Save button, ensure that “Script” is selected in the drop-down menu as the File Format.
3. Create an iCal Event
We are now finished with the AppleScript side of things and can move on to creating an iCal event with alarm to run the script we just created. Open iCal and double-click on the date that you would like to begin running the script. A New Event dialog will open; specify a title and time that you would like the AppleScript to be run.
To get to the time options, you may have to uncheck the “all-day” checkbox.
If you will be making this alarm recurring, select “Custom” from the Repeat drop-down menu. In this new dialog, select the frequency that applies to you, then select the days of the week that you would like it to occur. Since we work every week from Monday thru Friday, we selected the following options:
Every 1 week(s) on
M, T, W, T, F
When you have finished tweaking the repeat section for your schedule, click on the OK button.
If you only work every other week, configure it to use “Every 2 week(s) on.”
4. Add an AppleScript to Your Event
To add our AppleScript to the event, navigate back to the event you just created and select “Run Script” from the alarm section of the dialog. You will be presented with a file selection dialog. Navigate to the location where you saved the AppleScript. Click on the script file, and then click Select.
You can only add one AppleScript per alarm you create for the event.
After you have selected your script, you will be returned back to the event listing where you will need to add a few additional details about when the script will be run on your Mac. Underneath the script’s name, customize the launch to say “0 minutes before”. This will cause the script to be run at the event start time (ex. 9 o’clock in the morning).
The script will be run automatically whenever the start time is reached.
After you have configured this event, click “Done.” If you have scheduled this as a recurring event, your calendar will reflect the new events. Remember that iCal alarms will only work when your computer is turned on and not in sleep mode. If your computer is asleep, the script will be run automatically when you wake it up or turn it on after the alarm time has already passed.