Improved Exchange vCal support for Mail

Oct 20, '03 10:00:00AM

Contributed by: skater_odisy

I just got the hint a little while ago about support for Outlook meeting request support in Mail, and it worked well. I've improved it now to support updated meetings and a little extra automation. To set this up, follow the instructions in this other hint. Then use this script in place of the one in the other page. You must also change the file path in the third line down to a directory that exists. If anyone wants to implement a way to choose a directory automatically, that would be cool, I just didn't want to bother with it. Also, event cancellations aren't supported yet. I'll probably add this functionality soon unless someone else does first ... enjoy!

[robg adds: I haven't tested the following script...]


property beginTag : "BEGIN:VCALENDAR"
property endTag : "END:VCALENDAR"

property filePath : "Macintosh HD:Users:jon:Documents"

on perform_mail_action(info)
 tell application "Mail"
  set theMessages to |SelectedMessages| of info
  repeat with thisMessage in theMessages
   set thisContent to content of thisMessage
      
   if (thisContent contains beginTag) ¬
   and (thisContent contains endTag) then
       
    -- extract vCalendar from message 
    set thisCal to ¬
    text from character (offset of beginTag in thisContent) ¬
    to character ((offset of endTag in thisContent) ¬
    + (length of endTag)) of thisContent
       
    -- Get the UID of the event. Outlook creates a user id that
    -- follows the pattern /([a-z|A-Z|0-9]{71})\s([a-z|A-Z|0-9]{41})/
    set UIDOffset to ((offset of "UID:" in thisCal) + 4)
    set theUID to ¬
    text from character UIDOffset to character (UIDOffset + 70) of thisCal & ¬
    text from character (UIDOffset + 73) to character (UIDOffset + 113) of thisCal
        
    set eventExists to false
    set UpdateTheEvent to false
    tell application "iCal"
     repeat with theCalendar in calendars
      set theEvent to (event {} of theCalendar whose uid is theUID)
      try
       if (uid of theEvent is theUID) then
        set eventExists to true
        set theReply to display dialog ¬
        "This event already exists, what would you like to do?" ¬
        buttons {"Decide Later", "Update Event"} ¬
        default button "Update Event" giving up after 30
        if button returned in theReply is "Update Event" then
         set UpdateTheEvent to true
         delete (event {} of theCalendar whose uid is theUID)
        end if
       end if
      end try
     end repeat
    end tell
      
    if (UpdateTheEvent is true or eventExists is false) then
     set thisFileName to filePath & ":temp.ics"
     tell application "Finder"
      if exists file thisFileName then
       delete file thisFileName
      end if
     end tell
     set thisFile to open for access thisFileName with write permission
     write thisCal as string to thisFile
     close access thisFile
     tell application "Finder"
      open file thisFileName
     end tell
    end if
   end if
  end repeat
 end tell
end perform_mail_action

Comments (0)


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