iCal Alarm script - how to find the current event

Hi!

I want to start a script with a recurring iCal event. The script needs to find it’s starting and ending time and also some information like the location and the notes. But how do I get this information? How can the script access it?

Model: PowerBook G4
AppleScript: 1.10.7
Browser: Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.8.1.6) Gecko/20070802 SeaMonkey/1.1.4
Operating System: Mac OS X (10.4)

Hi,

You might want to start with reading the dictionary for iCal to learn its various properties and elements. You can do that in Script Editor’s “open dictionary” command and then browse to get to iCal.

At the same time, you can download some script apps at scriptbuilders, e.g., “open-file-Alarm Creator” which is editable and shows you how to access iCal’s various features like recurrent alarm, start date, end date, etc., as well as other iCal-targeted scripts.

Good luck.

archseed :slight_smile:

Thanks for the well-known standard reply. :wink: There is nothing that will give you the “current event” and there is no documentation at all, which parameters are sent to which handler when the script is called. Maybe there is some undocumented “on alert(event_id)” handler but I couldn’t find any documentation.

The only scripts I found up to now don’t work in a reliable way. They either don’t work correct at all, like “the last event is always the current”, which is simply wrong, or they are unreliable like seaching for an event that starts in a time frame around the current time, and some don’t work with recurring events.

Skeeve;

A couple of things you should know:

  1. iCal only stores one instance of recurrent events on the date of entry of the recurring event, so they don’t show up again unless you find them and calculate whether one of them occurs in your time span. That means you must look at all events in the span over which current recurring events might have been entered, check if they have a recurrence property, and from that deduce whether one occurs in your span.

  2. You don’t say how many calendars you want to look at, so I’ve whipped up this little example assuming all.

set now to date "Tuesday, October 9, 2007 12:00:00 AM"
set early to now - 24 * hours
set late to now + 24 * hours
set currentEvents to {}
tell application "iCal"
	set C to calendars
	repeat with aCal in C
		set N to name of aCal
		set end of currentEvents to (N & ": " & summary of (events of aCal whose start date > early and start date < late))
	end repeat
end tell

Hi,

OK, I wasn’t sure what you needed but going back to your post, I think I can now see what you want to do. I can give you a few possible leads based on my quick tests but you still have to work on it.

Here are some possible ways to extract an event and get its properties, viz., start date, end data, recurrence, etc. I think that you can extract the event from your calendar using the property “summary” which usually refers to the name of the event as Unicode text. Or, you can extract the UID of the event if you know its precise order in the calendar that contains the event.

I did try to experiment extracting the summary (or event name) of my “Home” calendar where I created a simple alarm event with a given name and put the summary in a list. That can be done successfully but the problem is getting the properties. It seems that the list is actually a list of records so if you know how to single out the elements of the list of records, then you can identify your event and get the properties that you need.

I have no experience working with records or list of records so I will leave it up to you but I will keep checking if I can be of further help.

archseed :slight_smile:

Hi Skeeve,

I decided to do some more experiments with iCal - the usual thing that I do when I can’t get anything quickly from this forum. It’s a “trial and error” thing, of course, but that makes it even more interesting and I learn more on my own in the process.

The events in any calendar and information on their properties can, indeed, be extracted. I think this is what you want, right?

What I did to test this out is create two events in iCal’s calendar “Home” and then try to extract the information via AppleScript. It’s the properties of the second event “testArchiver” (as you may note in the script below) that I targeted specifically.


tell application "iCal"
	activate
	set thisCalendar to "Home"
	set thisEvent to second event of calendar thisCalendar --gives the second "testArchiver" that I created in calendar "Home"
	get summary of thisEvent --returns "testArchiver"
	get start date of thisEvent -- returns date "Saturday, December 15, 2007 11:00:00 PM"
	get end date of thisEvent --date "Saturday, December 15, 2007 11:01:00 PM"
	get recurrence of thisEvent -- returns "" (for no recurrence); "FREQ=DAILY;INTERVAL=1" (for daily repeat)
end tell

I think other information like location can be extracted the same way; in my event example, I did not set up any location so I could not test it.

If the above does not answer your needs, let me know. But, of course, I hope that the test script above could get you going.

Good luck.

archseed :smiley:

Hi Skeeve,

Here’s a more complete script to include the Notes and the Location of the event.


tell application "iCal"
	activate
	set thisCalendar to "Home"
	set thisEvent to second event of calendar thisCalendar --gives the second  event"testArchiver" that I created in calendar "Home"
	get summary of thisEvent --returns "testArchiver"
	get start date of thisEvent -- returns date "Saturday, December 15, 2007 11:00:00 PM"
	get end date of thisEvent --date "Saturday, December 15, 2007 11:01:00 PM"
	get recurrence of thisEvent -- returns "" (for no recurrence); "FREQ=DAILY;INTERVAL=1" (for daily repeat)
	get description of thisEvent --returns the note for this event as "This is a sample event to test if its properties can be extracted via simple script."
	get location of thisEvent --returns "2700 Ulloa Street, San Francisco, CA 94116"
end tell

I hope this completely addresses your need.

Good luck.

archseed :smiley:

This thread was asking “how to find the current event”

This do not work:


tell application "iCal"
	tell calendar "Home"
		set thisEvent to last event of me
-- whatever you wanna do
	end tell
end tell

and even using “first” or “second” instead of “last” generate a “Can’t get event” error

this does work:


set now to current date

tell application "iCal"
	tell calendar "Home"
		repeat with thisEvent in ((every event whose start date = now))
-- whatever you wanna do
		end repeat
	end tell
end tell

do you really need a repeat to get a single event that is starting now?

and yes, I’ve been looking at samples and reading libraries with no useful result. :wink:

Thanks,
Andrea

AppleScript: 2.0.1
Browser: Safari 528.16
Operating System: Mac OS X (10.5)