A script to easily add Outlook invites to iCal

Sep 12, '02 10:06:53AM

Contributed by: viega

Obnoxiously enough, Mail and iCal do not interoperate well with iCalendar invites sent through Outlook. There are several problems. First, Mail doesn't know what to do with the request... it simply lists the thing as "mime-attachment", and associates no application with it. Second, there are some elements of the MS format that iCal doesn't deal with properly.

I needed an easy solution to this problem. That is, if someone uses Outlook to send a meeting request, I need to be able to bring it up in iCal with one simple action. I first tried some AppleScript-based solutions, but they all had limitations.

My solution uses some Unix shell scripting. It allows you to open up Outlook requests simply by dragging the "mime-attachment" to the desktop. First, open up Terminal, and run the command:

 % mkdir ~/bin
Then put the following text into a file called ~/bin/ical_convert:
#!/bin/bash

cd "/Users/viega/Desktop/"
item=mime-attachment

while "true"; do
if [[ -e $item ]]; then
sed "s/ORGANIZER\:MAILTO\:.*/&xxxFRED&/" $item |
sed "s/xxxFREDORGANIZER//" | sed "s/ORGANIZER\:/ORGANIZER\;CN\=/" |
sed "s/CN\=MAILTO\:/CN\=/"> /tmp/iCal.ics
rm $item
open /tmp/iCal.ics
fi
sleep 1
done
Note that the line starting with "#!" needs to be the first line of the file, and that the "sed" line has been shown on three lines. Enter it as one continuous line with a space replacing each shown line break.

Next, run the commands:
 % chmod +x ~/bin/ical_convert
% ~/bin/ical_convert &
The ampersand causes the program to start running, while allowing you to type more commands. Now, you can just drag the attachment to the Desktop, and everything else will happen automatically.

The big issue is that you have to start up ~/bin/ical_convert every time you reboot the computer. One might put a little launcher program into StartupItems (just be sure to ensure the program isn't already running). I personally use the bash shell, and insert the following code into my .profile:
progname=ical_convert

if [[ `ps -auwwwx | grep $progname | grep -v grep` ]]; then
echo "Ical converter script already running."
else
echo "Starting ical conversion script."
~/bin/ical_convert&
fi
You could do a more precise check by dropping a PID into a well-known file and checking that, but whatever.

Another issue is that you should avoid putting files named "mime-attachment" onto your desktop unless you want them to be processed by iCal and deleted. If that bugs you, you could create a folder somewhere else, and change the magic path to point to that folder instead of the desktop. I personally prefer the ease of use of not having to hit a small target when I drag and drop.

Comments (14)


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