Set iChat status based on iCal event alarms

Dec 02, '09 07:30:00AM

Contributed by: Andrew J Freyer

I wrote a small script that, using iCalBuddy, will set your iChat status based on the name of whichever iCal event calls the script as an alarm. Here's how it works.

First, save this as a script in AppleScript Editor. I have saved it as iCal Event to iChat:

set theEventName to (do shell script "/usr/local/bin/icalbuddy -ic \"Some\ Calendar\" -eep \"*\" -nc -b \"\" -n -li 1 eventsToday")

if (theEventName is not "") then
  tell application "iChat"
    set status to away
    set status message to "I am attending " & theEventName & "."
  end tell
end if
Then, in iCal, and create a new event (Planning Meeting or whatever) on a calendar. Set the Alarm Type to run your new AppleScript (iCal Event to iChat), and set it to run one minute after the event starts. Then, one minute after the event starts, your iChat status will change to I am attending Planning Meeting. This will also work for repeating events, but it will use the first alphabetical event if more than one event occurs at one time.

The reason that the alarm should be set after the event begins is that the return value from iCalBuddy is the current or next event. Therefore, if two events are immediately sequential, a "before" alarm will set the iChat status as the title of the current event, not the event that is actually calling the script.

If You are using Chax and Snow Leopard, use this code:
set theEventName to (do shell script "/usr/local/bin/icalbuddy -ic \"Some\ Calendar\" -eep \"*\" -nc -b \"\" -n -li 1 eventsToday")

if (theEventName is not "") then
  tell application "Chax" to activate
  delay 2
  tell application "iChat"
    set status to away
    set status message to "I am attending " & theEventName & "."
  end tell
end if
[robg adds: I haven't tested this one.]

Comments (2)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20091119112000571