find event title in applescript triggered by that event?

hi there

i have an applescript which get triggered by several ical events (each triggers the script via alarm → run script). how can the script find out the title of the event which triggered it?

i found similar questions ion forum already, but none did answer this question… if somebody knows anything about, hep would be much appreciated!

thanks, olli

Model: macbook pro
Operating System: Mac OS X (10.6)

I thought this query gave me a sense of déjà vu! I wrote something similar last month for the AppleScript-Users list.

It’s not possible for a script to find out directly what event triggered it. It can only make inferences by looking to see what events were due to trigger it at about the time it was actually triggered.

The script below returns a list of possible events. It only works with first-instances of events ” not where an alarm has been triggered by a repeat of a recurring event.

on getMyEvent()
	set now to (current date)
	set leeway to 5 -- Allow, say, 5 seconds for the script to respond to the alarm.
	
	tell application "System Events" to set myUrl to URL of (path to me)
	
	tell application "iCal" to set myInstances to (open file alarms of events of calendars whose filepath is myUrl)
	--> A list containing lists corresponding to the calendars, containing lists
	--> corresponding to the events, containing nothing or matching alarm(s).
	
	set candidates to {}
	repeat with c from 1 to (count myInstances)
		set thisCal to item c of myInstances
		repeat with e from 1 to (count thisCal)
			set thisEvnt to item e of thisCal
			repeat with alrm from 1 to (count thisEvnt)
				tell application "iCal"
					set eventRef to event e of calendar c
					set timeDiff to (start date of eventRef) + (trigger interval of item alrm of thisEvnt) * minutes - now
					if (timeDiff > -leeway) and (timeDiff < leeway) then set end of candidates to eventRef
				end tell
			end repeat
		end repeat
	end repeat
	
	return candidates -- List of possible triggering events.
end getMyEvent

set candidates to getMyEvent()

-- Then loop through the returned list of possible events (hopefully only one) with iCal and get each one's summary.

thanks heaps for this, nigel, but it’s a bummer that ical does not hand the event details in itself!

anyway, i’ll try i out! great workaround!

olli