Add ics file to specific ical calendar.

Hi,

I want to add an ics file to a specific ical calendar. If I use the following script to do this:


tell application "iCal"
	activate
	delay 2
	try
		open "/Users/jonasyde/Downloads/stuntnacht.ics"
	on error
		do shell script "open /Users/jonasyde/Downloads/stuntnacht.ics"
	end try
	delay 2
	tell application "System Events"
		tell window "Activiteiten toevoegen"
			delay 2
			click pop up button 1
			delay 2
			click menu item "Uitgaan" of menu 1 of pop up button 1
			delay 2
			click button "OK"
		end tell
	end tell
end tell

but I get the following error:

error "System Events kreeg een fout: window \"Activiteiten toevoegen\" kan niet worden opgevraagd. " number -1728 from window "Activiteiten toevoegen"

Apparently the script can’t find the “Activiteiten toevoegen” window, although it is the correct spelling (double checked) and the window is already fully loaded when the error appears.

(Since the script doesn’t recognize the window, using the code from http://macscripter.net/viewtopic.php?id=29010 doesn’t work)

Hi, Metalhammer.

You have to tell System Events which application process owns the window. My Dutch is a little rusty, so I can’t tell if that’s meant to be iCal here or not. :slight_smile: (Edit: OK. Comparing the script with the one in the other thread, I can now see that it is.)

tell application "System Events"
	tell application process "iCal"
		tell window "Activiteiten toevoegen"
			-- etc.
		end tell
	end tell
end tell

It would be better if this wasn’t inside the ‘tell application “iCal”’ block.

Thanks a lot! That did it!