Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

A revised iCal and Outlook calendar script Apps
I really wanted to use iCal to send integrated invites to Outlook, but there are two problems:
  1. Timezone -- Outlook doesn't support TIMEZONE properly.
  2. Attachments -- iCal sends the ICS file as an attachment
I quickly found this older hint here, but it did not work! So I fixed it. Just replace the send_mail_sbrp function in the /Applications: iCal.app: Contents: Resources: Mail.scpt file with this improved version.

[robg adds: There are lots of comments to the old hint that may help as well, but I felt it was worth an update given the amount of time that has passed since it first ran. I have not tested this one.]
    •    
  • Currently 2.00 / 5
  You rated: 1 / 5 (4 votes cast)
 
[14,221 views]  

A revised iCal and Outlook calendar script | 9 comments | Create New Account
Click here to return to the 'A revised iCal and Outlook calendar script' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
doesn't work for me on iCal 2.0
Authored by: gabrielradic on May 16, '05 03:57:52AM

I had a hard time guessing the encoding of the linked file.

Is this iCal pre 2.0 only? I just went with UTF-8, cause that "looked" right, but the script returns errors with iCal 2.0.



[ Reply to This | # ]
doesn't work for me on iCal 2.0
Authored by: Paul Schaap on May 16, '05 10:12:45AM

Hi There,

A couple of things here.
1) I had hard coded my home directory while testing, so change /Users/schaappa/ to /tmp/
2) Backup Backup Backup
3) The idea is to just replace the on function in the /Applications/iCal.app/Contents/Resources/Mail.scpt, NOT the whole script

To edit the script open a terminal and type :-
open /Applications/iCal.app/Contents/Resources/Mail.scpt

And replace the function (on!) of the same name with the script below
-------------------------------------------------------------------------------------
-- Mail.scpt hack for Outlook compatibility
on send_mail_sbrp(subjectLine, messageText, myrecipient, invitationPath)
set pfile to POSIX file invitationPath
set myfile to pfile as alias

try
-- define a carriage return
set cr to (ASCII character 13) & (ASCII character 10)

-- retrieve the user's name and e-mail
set listOfAccounts to {}
tell application "Mail"
repeat with oneAccount in every account
set listOfAccounts to listOfAccounts &
{"\"" & (get full name in oneAccount) & "\" <" &
(get email addresses in oneAccount) & ">"}
end repeat
end tell

if ((get length of listOfAccounts) is 1) then
set theAccountTouse to get first item of listOfAccounts
else
set theAccountTouse to
choose from list listOfAccounts
default items (get first item of listOfAccounts)
with prompt

"Please select which mail account to send the invitation from:" without multiple selections allowed and empty selection allowed
end if

-- open and read the ical event file to insert into an e-mail
set myEventFileHandle to
open for access myfile without write permission
set myEventFileContent to read myEventFileHandle
close myEventFileHandle

-- remove the timezone info from the calendar event
-- to make compatable with outlook
set toss to false
set newEventFileContent to ""
set last_line to false
repeat with theLine in paragraphs of myEventFileContent
if theLine contains "BEGIN:VTIMEZONE" then
set toss to true
else if theLine contains "END:VTIMEZONE" then
set last_line to true
set toss to false
end if
if toss is false then
if last_line is true then
set last_line to false
else
set newEventFileContent to newEventFileContent & theLine & cr
end if
end if
end repeat
set myEventFileContent to newEventFileContent

-- pre-pend mail headers to the event contents
set myNewEmailText to
"From: " & theAccountTouse & cr &
"To: " & myrecipient & cr &
"Subject: " & subjectLine & cr &
"MIME-Version: 1.0" & cr &
"Content-Type: text/calendar; method=REQUEST;" & cr &
" charset=\"utf-8\"" & cr &
"Content-Transfer-Encoding: 7bit" & cr &
"Importance: Normal" & cr & cr &
myEventFileContent
-- " name=\"meeting.ics\"" & cr &

-- create a random event file name
set tempMailName to (random number from 1 to 1000000) & ".ics"
set aliasTempMail to "/tmp/" & tempMailName

-- write the new e-mail to a temp file
set myEventFileHandle to
open for access (POSIX file aliasTempMail as string) with write permission
write myNewEmailText starting at 1 to myEventFileHandle as «class utf8»
close myEventFileHandle

-- use SENDMAIL to send the file with proper headers
do shell script "cat " & aliasTempMail & " | sendmail -oi -t "

-- delete the temp file
do shell script "rm " & aliasTempMail
on error errMsg
display dialog errMsg
end try
end send_mail_sbrp
-------------------------------------------------------------------------------------



[ Reply to This | # ]
doesn't work for me on iCal 2.0
Authored by: drtofu on Mar 10, '06 01:55:44AM
Hi Paul,

Thanks for your code. I was still having problems importing due to Outlook's non-compliance with the iCalendar standard, so I took your script and modified it a bit for my needs and it's working great.

The changes I made:

  • The script now uses Mail.app as the sender (so sent invites appear in my sent mail folder)
  • Doesn't ask for a sending account (since I only use my primary account).
  • I restricted the stripping to activate only for a specific domain because they're the only Outlook users I interact with.
  • It also strips out the TZID portions because Outlook 2003 was choking on it. Note: I've hard coded the TZID string to my particular time zone, so an obvious improvement would be to remove that portion of text based by removing the characters from the semicolon to the colon (non-inclusive) instead.

    -Bryan

    How to use:

    In Terminal, open /Applications/iCal.app/Contents/Resources/Mail.scpt
    ## Remember to back up your original Mail.scpt file!

    Replace the send_mail_sbrp function with the following. Keep all other functions as they are.

    
    -- Outlook 2003 is still not RFC 2445 compliant, so this script strips out the VTIMEZONE and TZID portions of the the .ics file that confuse Outlook (causing, for example, the "Gregorian"/"Lunar" import error in Outlook 2003)
    -- I've restricted the script to recipients in a specific domain because I don't want to affect notifications to potential non-Outlook recipients.  Feel free to change or remove that logic to fit your particular needs.
    
    -- Note that the invitation times will only be accurate for Outlook users in the same time zone as the sender.  This is because Outlook doesn't know how to handle time zones (it expects GMT (i.e. Zulu) times).  Ideally, this script would translate all times to GMT, but that's more than I need right now, so the script just strips out all time zone information, and Outlook assumes the imported times refer to local time.
    
    -- In Terminal, open /Applications/iCal.app/Contents/Resources/Mail.scpt
    -- ## Remember to back up your original Mail.scpt file!
    -- Replace the send_mail_sbrp function with the following.  Keep all other functions as they are.
    
    
    -- Mail.scpt hack for Outlook compatibility - Bryan's version
    on send_mail_sbr(subjectLine, messageText, myrecipient)
    	tell application "Mail"
    		set mymail to (make new outgoing message at the beginning of outgoing messages with properties {subject:subjectLine, content:messageText})
    		tell mymail to make new to recipient at beginning of to recipients with properties {address:myrecipient}
    		send mymail
    	end tell
    end send_mail_sbr
    
    -- Mail.scpt hack for Outlook compatibility - Bryan's version
    on send_mail_sbrp(subjectLine, messageText, myrecipient, invitationPath)
    	set pfile to POSIX file invitationPath
    	set myfile to pfile as alias
    	
    	try
    		if myrecipient contains "wanderingspoon.com" then
    			-- if appointment going to Thy, then parse for outlook
    			-- define a carriage return
    			set cr to (ASCII character 13) & (ASCII character 10)
    			
    			-- open and read the ical event file to insert into an e-mail
    			set myEventFileHandle to 
    				open for access myfile without write permission
    			set myEventFileContent to read myEventFileHandle
    			close myEventFileHandle
    			
    			-- remove the timezone info from the calendar event
    			-- to make compatable with outlook
    			set toss to false
    			set newEventFileContent to ""
    			set last_line to false
    			repeat with theLine in paragraphs of myEventFileContent
    				if theLine contains "BEGIN:VTIMEZONE" then
    					set toss to true
    				else if theLine contains "END:VTIMEZONE" then
    					set last_line to true
    					set toss to false
    				end if
    				if toss is false then
    					if last_line is true then
    						set last_line to false
    					else
    						if theLine contains ";TZID=US/Pacific" then
    							set theLine to searchReplace(theLine, ";TZID=US/Pacific", "")
    						end if
    						set newEventFileContent to newEventFileContent & theLine & cr
    					end if
    				end if
    			end repeat
    			
    			-- create a random event file name
    			set aliasTempMail to "/tmp/" & (random number from 1 to 1000000) & ".ics"
    			
    			-- write the new event to a temp file
    			set myEventFileHandle to 
    				open for access (POSIX file aliasTempMail as string) with write permission
    			write newEventFileContent starting at 1 to myEventFileHandle as «class utf8»
    			close myEventFileHandle
    			
    			set pfile to POSIX file aliasTempMail
    			set myfile to pfile as alias
    			-- display dialog "ready for Outlook"
    		else
    			-- display dialog "standard .ics format"
    		end if
    	on error errMsg
    		display dialog errMsg
    	end try
    	
    	try
    		tell application "Mail"
    			set mymail to (make new outgoing message at the beginning of outgoing messages with properties {subject:subjectLine, content:messageText})
    			tell mymail to make new to recipient at beginning of to recipients with properties {address:myrecipient}
    			tell mymail
    				tell content
    					make new attachment with properties {file name:myfile} at after the last word of the the last paragraph
    				end tell
    			end tell
    			send mymail
    		end tell
    	on error errMsg
    		display dialog errMsg
    	end try
    end send_mail_sbrp
    
    to searchReplace(thisText, searchTerm, replacement)
    	set AppleScript's text item delimiters to searchTerm
    	set thisText to thisText's text items
    	set AppleScript's text item delimiters to replacement
    	set thisText to "" & thisText
    	set AppleScript's text item delimiters to {""}
    	return thisText
    end searchReplace
    
    


    [ Reply to This | # ]
  • A revised iCal and Outlook calendar script
    Authored by: cupertinox on May 17, '05 07:54:41PM

    i used paul's version (without funny characters) and patched mail.scpt. however, if i choose an ical event, ctrl click it and say "mail event", still old mail.app comes up - which tells me that my outlook friends on their pcs cannot use this in their calendars. what is wrong? incidentally, there is also an identical mail.applescript file in the resources folder of ical.app, for what reason i wonder. btw, too bad that apple has not picked up the ball yet on making outlook work smoother with ical and vice versa. a new annoying thing is that if an event is not mailed to me in person but via a mailing list, ical complains that no email address in the invitation matches my own and refuses to add the event. only drag and drop helps.



    [ Reply to This | # ]
    A revised iCal and Outlook calendar script
    Authored by: Paul Schaap on May 17, '05 10:47:27PM

    This still uses Mail.app but what it does is to format the mail headers etc in a format that Outlook will understand. Mail.app does not affect the structure so it does work with Outlook.

    The Mail.applescript is the TEXT version of the 'compiled' Mail.scpt. Mail clearly uses the compiled version.

    Yeah, I wish Apple would change their script to my version ;-)

    The mailing list probably does not comprehend Content-type ...



    [ Reply to This | # ]
    A revised iCal and Outlook calendar script
    Authored by: roballen on Jul 15, '05 11:36:27AM

    Hi

    I've tried to follow this hint. Pretty sure I have, edited the file, compiled the script, and saved it.

    Closed and re-opened iCal, but it still sends the original attachment type. I'm running the latest and greatest version of OSX 10.4.2

    If I take the attachment from the email, and edit it directly then send it, it all works fine.

    Anyone shed any light?

    Thanks

    Rob



    [ Reply to This | # ]
    A revised iCal and Outlook calendar script
    Authored by: henkez on May 19, '05 08:05:27AM

    I havn't tried it yet but I sure will!

    Sure you can wonder why Apple hasn't incorporated this in iCal but the thing is that the problem is with MS Outlook because Outlook DOES NOT follow iCal RFC standards. So, should Apple change to non-standards just to satisfy Outlook or should MS developers learn how to write good code :) Sorry couldn't help it.

    Love the initiative!

    //henke



    [ Reply to This | # ]
    A revised iCal and Outlook calendar script
    Authored by: jsaintjohn on May 19, '05 09:07:03PM

    Does anyone know of a program that can be loaded on MAC OSX that will allow iCal to accept an appointment from outlook. Meaning that an invite is sent to you via e-mail from Outlook and iCal can accept. Please help if possible.

    J



    [ Reply to This | # ]
    A revised iCal and Outlook calendar script
    Authored by: roballen on Jul 15, '05 09:55:14AM

    There is an option in Outlook under Actions I think to send invites as iCalendars.

    This works fine.

    The Address they send the invite to though has to match your address card in the Address Book application.



    [ Reply to This | # ]