getting event properties from iCal alarm script

I’m trying to write a script that will email attendees of an iCal repeating event a reminder every time the event repeats. I have looked into iCalMail 1.4, but it doesn’t do what I need – in part because I don’t want to set up a separate calendar for these events, and because it doesn’t appear to handle repeating events, and because it sends out information that I don’t want to send.

However, I can’t seem to access the event’s properties from the script. Probably this is because I don’t know how to identify the event in the script. Here’s what I have so far:

tell application "iCal"
	show event
	set the_time to start date of event
	set mail_address to email of first attendee
end tell

set the_body to "A message including " & the_time & "."
set the_subject to "Event Reminder"


tell application "Mail"
	open
	set new_message to (make new outgoing message at end of outgoing messages)
	tell new_message
		set visible to true
		make new to recipient at end of to recipients with properties {address:mail_address}
		set subject to the_subject
		set content to the_body
		send
	end tell
end tell

I’m not to worried about the “Mail” handler yet, since I never get there. The error I receive is that the script can’t get the start date of the event. Any clues how I can tell it which event to get the start date for? I want this script to work for more than one repeating event, but I can’t seem to find out how to name the event that triggered the alarm.

Kendall

Hi Kendall,

an event must be referenced and can be filtered like this

tell application "iCal"
	tell (1st event of calendar 1 whose summary is "whatever")
		show it
		set the_time to start date
		set mail_address to email of first attendee
	end tell
end tell
.

Many thanks! This gets me a step closer in the right direction. However, I still have two problems with iCal.

  1. With this solution, I need a different script for every event (though they would be easy to alter with just the summary descriptor changing). I’d like to be able to identify the even where the alarm just went off, but I don’t see any way to test for that. Nor do I see a way to make the event show when turning on the alarm.

  2. I’m starting to wonder whether I can even get a good date for the next recurrence of the event form iCal. The start date will probably report the initial start not the next date. However, I will test it and see what information I can at least glean from the start date – the day and time might be enough, if it reports that, since these are bi-weekly events and I could say ‘next week Xday at Y:00’

At least I’m much closer and can actually access the email address of an attendee with this script. I wish iCal could pass a few parameters to the script when it runs a script alarm! Or that it let you send reminders to attendees by email, instead of just sending them to yourself.

What’s about this technique.:

Create the first event (without recurrence) and an alarm which triggers a script.
This script sends the mail to the attendees and creates the next event (and so on).

With the parameters of the recurrence the date can be certainly calculated

Thanks again. I decided to work with your first suggestion, though, as it looks like it will involve less scripting for me. I just need a template with the main script and then I can create individual scripts by replacing “PutNameHere” with the attendee’s name (which is in the summary of the event).

Here’s what works in my tests:

tell application “iCal”
tell (1st event of calendar “Conferences” whose summary contains “PutNameHere”)
show it
set start_date to start date as string
set mail_address to email of first attendee
end tell
end tell

set the_time to (word 5 of start_date & “:” & word 6 of start_date & last word of start_date)
set the_day to (first word of start_date)

tell application “Mail”
set new_message to (make new outgoing message at end of outgoing messages)
tell new_message
set visible to true
make new to recipient at end of to recipients with properties {address:mail_address}
set subject to “Your Conference”
set content to "Please remember to turn in work for your next conference on " & the_day & " at " & the_time & “. Any additional text”
send
end tell
end tell