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: 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 | # ]