Patching iCal to Send Alarms Via RSS
At work, I rarely check my e-mail, so I decided to see if I could have iCal 1.5 send me an RSS notification. After a little looking around, I discovered that you can patch iCal's e-mail notification to post to a blog via XML-RPC and Applescript.
This is a long one, so do the Continue reading thing.
Note: I have only tried this on iCal 1.5.1 and cannot guarantee it will work on any other version. If iCal is upgraded in the future, this will stop working.
Resources:
Mac OS X Hints - scroll to the bottom of the comments
Objective Labs - Blogger API Testing Script
Give these a quick look over before starting.
Instructions:
So we're not really having iCal push RSS, so you need to have a running blogging system that uses the Blogger API to take advantage of this. I run Movable Type for my blog and it works fine.
First things first. Backup iCal. Really.
Okay now that we're past that, do I right click on iCal and click "Show Package Contents. Open up Contents and then Resources and look for Mail.applescript. Copy this to your desktop and then open it in Script Editor.
As you can see, this is pretty much standard applescript in here. So we're going to add in some properties from the Objectivelabs script so we can call a modified fuction later. At the top of the file, right after the --iCal line, paste in the following:
property username : "username" -- your username
property myPassword : "password" -- your password
property apiurl : "http://myMTblog.com/cgi-bin/mt-xmlrpc.cgi" -- the complete api url
property blogid : "1" -- Id of the weblog you'd like to post to
property publish : true
property appkey : "4FCE1E1F9E2DC89044F09D583390AB8A36F4903E"
This stuff is important. Make sure that your username and password are the same as you use to log into your blog. The URL is the path to your XMLRPC interface. In MT it's mt-xmlrpc.cgi, in wordpress it's xlmrpc.php. The id of your blog can be tricky. The easiest way to get your blog ids is to run the Objective Labs script with only the username password and apiurl properties established. That will give you a list of the names and ids of your blogs. Plop in the correct id there. I would recommend just making a new blog for your alerts that you can check independently of the others.
Next, find the function send-mail_sbr. replace the function with this:
on send_mail_sbr(subjectLine, messageText, myrecipient)
newPost(blogid, messageText, publish)
end send_mail_sbr
This tells iCal to call the newPost function instead of sending mail. The date, title, and notes of the iCal event are published to the blog. Where is this function you may ask? Well we're adding it now. Scroll to the very bottom of the file and then paste this code in after everything else.
-- Sends the XML-RPC code to the remote server
on tellBloggerAPI(methodName, params)
using terms from application "http://www.apple.com"
-- any url works here. Fools applescirpt into using xml-rpc terms
tell application (apiurl as text)
set myResult to call xmlrpc {method name:methodName, parameters:{appkey} & params}
return myResult
end tell
end using terms from
end tellBloggerAPI
-- Creates a new post, and possibly it is published
on newPost(blogid, content, publish)
set params to {blogid, username, myPassword, content, publish}
return tellBloggerAPI("blogger.newPost", params)
end newPost
Okay, we're done here. Save the file. Now we're going to move that file into the iCal bundle and give it the right permissions. You backed up iCal right? Okay good. Assuming you saved the file to the desktop and iCal is in the root of the applications folder, do the following terminal magic:
mv ~/Desktop/Mail.applescript /Applications/iCal.app/Contents/Resources/Mail.scpt
sudo chown root:admin /Applications/iCal.app/Contents/Resources/Mail.scpt
sudo chown 664 /Applications/iCal.app/Contents/Resources/Mail.scpt
And.... we're.... spent. Okay, now iCal will post to our blogs when it's open. To make sure it does the same thing when it's closed, you have to patch a file in the iCal helper app. Thankfully it uses the same script so we can just pop the following in the terminal:
mv ~/Desktop/Mail.applescript /Applications/iCal.app/Contents/Resources/iCal\ Helper.app/Contents/Resources/Mail.scpt
sudo chown root:admin /Applications/iCal.app/Contents/Resources/iCal\ Helper.app/Contents/Resources/Mail.scpt
sudo chown 664 /Applications/iCal.app/Contents/Resources/iCal\ Helper.app/Contents/Resources/Mail.scpt
Now all your alarms for which you have specified e-mail as your alarm choice will instead be posted to your blog. Recipient doesn't matter as it is ignored anyway. Of course, e-mail alerts will no longer work, but if you want to do both, you can just have applescript call the post function right after the e-mail function.
I tried having iCal call an Applescript from the "Open File" alarm option, but I couldn't get iCal to pass any information to the script like the title of the event or the note attached to it. If anyone knows how to do this I would love to hear it.
Conclusion:
I am using this script to remind me when bills are due since I spend so much time in my aggregator, and so little in my email these days. But you could also use it to post entries by including HTML in the notes section of your events. There are a lot of possible uses for this. Hope you enjoy it. Thanks to Objective Labs for the script and dbikel on macosxhints for his sendmail hack for iCal 1.5.


