Friday, January 20, 2012

iCal alarms for recurring subscribed events

iCal won't alarm on events in subscribed to calendars, such as Facebook.  I guess the originator of the event has to set whether to alarm or not.  So I spent a little time leaning AppleScript, and here's a script that does it.
on run the_calendars
    try
        length of calendars
    on error
        set the_calendars to {"Facebook"}
    end try
    
    set today to (current date)
    set this_day to day of today
    set this_month to month of today
    set to_display to ""
    
    tell application "Calendar"
        repeat with the_calendar in the_calendars
            log the_calendar
            tell calendar the_calendar
                repeat with the_event in every event
                    set the_date to start date of the_event
                    set the_day to day of the_date
                    set the_month to month of the_date
                    
                    if (the_month = this_month and the_day = this_day) then
                        set to_display to (to_display & summary of the_event as string) & return
                    end if
                end repeat
            end tell
        end repeat
    end tell
    
    if (length of to_display > 0) then
        tell application "Finder"
            activate
            with timeout of 86400 seconds
                display dialog to_display
            end timeout
        end tell
    end if
end run

Open up you AppleScript Editor, copy and paste, and save somewhere. Now, you'll need to have it run every day. So I learned a little about launchctl. Save the following script to ~/Library/LaunchAgents. I called mine 'edu.ucar.icalsubscriptions.plist'. You'll need to modify the Program path to where you saved your script, and possibly the time it runs if you don't like 0900. You might also need to change the name of the calendar to match the name of the calendar in iCal -- mine is called Facebook -- and you can have a list of them if you want.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC
     "-//Apple//DTD PLIST 1.0//EN"
     "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
    <dict>
        <key>Label</key>
            <string>edu.ucar.icalsubscriptions</string>

        <key>Program</key>
            <string>/Users/beaty-admin/iCalRecurring.app/Contents/MacOS/applet</string>
            

        <key>ProgramArguments</key>
            <array>
                <string>Facebook</string>
            </array>

        <key>StartCalendarInterval</key>
            <dict>
                <key>Hour</key>
                    <integer>9</integer>
                <key>Minute</key>
                    <integer>0</integer>
            </dict>

        <key>Debug</key>
            <true/>
    </dict>
</plist>

No comments: