Automaticly import ics-files to iCal

Hi, i found that script in this forum, it works, but i want to change some things, it will be great if you can help me because i have no experience with Apple scripting.

This is the script:


property theAttachmentPath : (path to desktop) as Unicode text
property add_events : "Importieren" -- The title of the "Add Events" dialog on your system.
property cal_name : "myCalendar" -- The name of the target calendar.

using terms from application "Mail"
	on perform mail action with messages theMessages for rule theRule
		tell application "Mail"
			repeat with This_Message in theMessages
				repeat with ma in mail attachments of This_Message
					set n to name of ma
					if n ends with ".ics" then
						save ma in file (theAttachmentPath & n)
						my import_to_iCal(theAttachmentPath & n)
					end if
				end repeat
			end repeat
		end tell
	end perform mail action with messages
end using terms from

on import_to_iCal(file_path)
	tell application "iCal"
		activate
		set c to (count events of calendar cal_name)
		ignoring application responses
			open file file_path
		end ignoring
	end tell
	tell application "System Events"
		tell application process "iCal"
			set frontmost to true
			tell window add_events
				repeat until (it exists)
					delay 0.2
				end repeat
				click pop up button 1
				repeat until (menu 1 of pop up button 1 exists)
					delay 0.2
				end repeat
				click menu item cal_name of menu 1 of pop up button 1
				repeat while (menu 1 of pop up button 1 exists)
					delay 0.2
				end repeat
				click button "OK"
			end tell
		end tell
	end tell
	tell application "iCal"
		repeat until ((count events of calendar cal_name) > c)
			delay 0.2
		end repeat
	end tell
	tell application "Finder" to delete file file_path
end import_to_iCal

There are two things i want to change:

  1. the script is not deleting the ics-file on the desktop in every case
  2. i want to delete the Email with the ics-file automaticly after import to iCal.

So can you tell me, how to safe the ics-file not to dektop but to the trash, and the import from the trash to iCal (can i substitute “desktop” in the script with “trash”). The trash will be cleaned from time to time.

Should i create a rule to delete Emails with an ics-file ? Then i think i have to be sure, that before deleting the email, the ics-file has to be imported to iCal.

As result of this, i want to have a workflow, that when i get a email with ics-file, that this ics-Event will be imported to iCal and there is nothing mor to delete (no email and no ics-file).

Thanks for your help

Mittagspause

Model: MacBook pro
AppleScript: actual
Browser: Safari
Operating System: Mac OS X (10.6)