Saving time with Mail, iCal, and AppleScript
August 13, 2008 at 11:48 AM by Dr. Drang
The purpose of computers is to automate boring, repetitive tasks; but too often we find ourselves at the computer doing boring, repetitive tasks just to satisfy the software. The solution threefold:
- use better software;
- learn to use the software; and
- write your own programs.
This morning I had a boring, repetitive task that I got done quickly by applying these three ideas.
I got an email from my younger son’s soccer coach with the schedule for the upcoming season. Before Leopard, I would have to enter all the dates and times into iCal “manually,” i.e. by typing everything in. There’d be some effort saved by using the clipboard and pasting certain parts of each entry, but the savings wouldn’t be big. If the games had a regular schedule, I could set up a repeating event and do much of the entry just once—applying the second idea above—but the schedule wasn’t regular. I could also apply the second idea by entering one “master event” for the first game, copying it, then pasting it into the days for the later games and adjusting the times. This may or may not be faster than manual entry, depending on how much adjustment would be needed. Regardless of the exact process I used, I would have to continually refer back to the email to make sure I had the dates and times right.
The new versions of Mail and iCal with Leopard allow me to use the first idea above. Mail now has Data Detectors, which recognize dates and times in emails and allow you to create a new iCal event from Mail with just two actions, a click and drag to select Create New iCal Event… from the Data Detector popup menu, and a confirmation click (or a press of the Return key) to finalize the entry. Here’s the popup menu:
And here’s the popup window with the event data:
Fourteen quick clicks and I have the whole schedule in my calendar. Mail has become better software because of Data Detectors.
(A couple of weeks ago, this article by Michael Tsai, describing how to turn Mail’s Data Detectors off, made the rounds of the usual Mac-related websites. I don’t understand the appeal of doing so. Tsai said he wanted Data Detectors disabled “because I never use them and they interfere with selecting text.” It’s a free country, and not using Data Detectors is his choice, even if it is a bad choice. But they really don’t interfere with selecting text. He may not like seeing the little arrow that appears next to a date when the mouse is over it, but it doesn’t get in the way of text selection. So he’s eliminating an improvement in the program, getting virtually nothing in return, and a bunch of Mac users applaud. Weird.)
The only problem with these automatically created events is their title. Mail gets the title from the Subject line of the email, which is a pretty good guess, but it isn’t the title I want. I could change the title for every event in the editable field of the popup window, but that would put me back doing repetitive, boring things again.
The solution is to use the third idea with this simple AppleScript:
1: tell application "iCal"
2: set soccer to every event in calendar "Home" whose summary is "Soccer Fall Schedule"
3: repeat with game in soccer
4: set summary of game to "Soccer game"
5: set location of game to "River Woods #1"
6: end repeat
7: end tell
The creation of this script may have been more work than typing “Soccer game” seven times, but it wasn’t boring or repetitive. And with Line 5, I got to clean up the text of the location field at the same time.
Even though I’m done entering this schedule, I’ve saved the AppleScript to use as a template or model for future scripts. All kinds of sports and school schedules can be handled the same way with just a few edits to the script.
Old habits often get in the way of improving efficiency. I could have used this same approach to save time entering baseball and swimming schedules earlier this year. But it took me a while to appreciate the value of Data Detectors, and I had to convince myself that the effort of writing the AppleScript would eventually be repaid. Now I’ll never go back to entering schedules by hand.