iCal alarm scripting: get the last event (or the alarm trigger)

I’m trying to put together an applescript to text-message me certain events by using an alarm to send an e-mail. The trouble is, I can’t seem to get the proper event. I read in another post here that I was looking for the “last event”, but that seems to return a totally random event, unrelated to whatever triggered the alarm. Here is the current code, for reference:


on getNextEvent()
	set theEventText to null
	tell application "iCal"
		activate
		set theEvent to the last event of calendar "School"
		set theEventText to summary of theEvent
	end tell
	return theEventText
end getNextEvent

Any suggestions?

I had a similar problem. What you’re script is really doing is getting the last event item of the calendar, not the last occured event. You can see my solution in iCalMail.

http://www.versiontracker.com/dyn/moreinfo/macosx/27322

I actually tried something along those lines originally, but it didn’t work for recurring events (i.e. the start date of a recurring event seems to be only its first occurrence.) Have you figured out a way around that, or do you have the same trouble?

Your solution being looping through all to find one with the right date/time?

Odd that iCal won’t give us the event that triggered the alarm.