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


Click here to return to the 'doesn't work for me on iCal 2.0' 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: 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 | # ]