get date's events from a calendar in iCal?

I can grab all the events in a specific calendar in ical and do stuff with them if I like. But I’m absolutely stumped as to how to get only the events which occur on a specific day from a specific calendar. How is one supposed to access only these particular events? I really really want to avoid having to attempt to parse and figure out all the potential combinations of RECUR and RRULE properties to determine when recurring events may fall on the day I’m currently searching. Is there anyway to let iCal do the heavy lifting for me there? It seems to do pretty well on it’s own, but how do I plug into this info?

Would any of you kind people perhaps have the uber cool ical scripting knowledge that I am currently lacking?

Thank you very much for any help.

Is this what you are looking for?

tell application "iCal"
	set mydate to date "Saturday, July 3, 2004 12:00:00 AM"
	tell calendar 1
		get events whose start date is greater than or equal to mydate and start date is less than (mydate + 24 * hours)
	end tell
end tell

Jim

That is an excellent little script and it does help me figure out a few things. However it does not take into account the possibility of events that were started previous to the specified date and just happen to occur on the specified date due to some wacky recurrence rule.

I’m looking to capture events that were started, for example, on the first monday of the month, but occur every monday thereafter until the end date, or until the count is up.
This is what’s really killing me. It seems that iCal has no simple command that will call up events which occur on a specific date/time. By all appearances one would have get the recurrence string property of each event and parse that complicated sucker to see if it would occur, or recur on the specified date. ick!

Thanks for the cool script though. It definitely is a good start and if you’ve got any more magic in your pocket, I’d love to see it.

Thanks,

~elmlish~

I thought I couldn’t figure it out because I’m a newbie. Darn, how frustrating! At least I know it’s not me. I sure hope Apple fixes this!

:x

Hi,

I tried this a while back and it is very frustrating. What you can try is just look at the recurrence types you currently use and parse these. It would help if Apple put out a list or something but the recurrence string is wierd. Sometimes, although the recurrence events are the same, the recurrence string may be different. This is part of the reason I abandoned trying to script this.

gl,

Being a newbie, I don’t really know how to parse anything. I when I peeked at what the recurrence properties actually look like, whew, I don’t know how anyone can do a thing with them. If someone has actually done this, I would love to see it.

Jessi

Hi,

Here’s how I started on this. First, the string looks something like this:

“:FREQ=YEARLY;INTERVAL=1;BYMONTH=1;BYDAY=3MO”

This is taken from the US Holidays calendar at Apple’s site. Now you need to remove the starting colon:

tell application “iCal”
set the_cal to first calendar whose title is “US Holidays”
set event_list to every event of the_cal
set e1 to item 2 of event_list – Martin Luther Day
set the_recur to (recurrence of e1)
set temp_rec to (rest of (text items of the_recur) as string) – remove starting colon
end tell

Here’s the result without the colon:

“FREQ=YEARLY;INTERVAL=1;BYMONTH=1;BYDAY=3MO”

Note that there are several ways to do things and it is up to you. Now I want to change this iCal record string into a list:

tell application “iCal”
set the_cal to first calendar whose title is “US Holidays”
set event_list to every event of the_cal
set e1 to item 2 of event_list – Martin Luther Day
set the_recur to (recurrence of e1)
set temp_rec to (rest of (text items of the_recur) as string) – remove starting colon
– make list of criteria
set def_tid to (AppleScript’s text item delimiters)
try
set AppleScript’s text item delimiters to {“;”, “=”}
set iCal_rec to (text items of temp_rec)
set AppleScript’s text item delimiters to def_tid
on error
set AppleScript’s text item delimiters to def_tid
beep 2
return
end try
end tell
return iCal_rec

Result:

{“FREQ=YEARLY”, “INTERVAL=1”, “BYMONTH=1”, “BYDAY=3MO”}

This is almost looking like an AppleScript record. The labels are FREQ, INTERVAL, BYMONTH, and BYDAY and the values are obvious. Now you need a list of labels and their possible values. This would make things easy. If you had this list, then you might do something like this:

property rec_template : {freq:missing value, bymonth:missing value, byday:missing value}

tell application “iCal”
set the_cal to first calendar whose title is “US Holidays”
set event_list to every event of the_cal
set e1 to item 2 of event_list – Martin Luther Day
set the_recur to (recurrence of e1)
set temp_rec to (rest of (text items of the_recur) as string) – remove starting colon
– make list of criteria
set def_tid to (AppleScript’s text item delimiters)
try
set AppleScript’s text item delimiters to {“;”, “=”}
set iCal_rec to (text items of temp_rec)
set AppleScript’s text item delimiters to def_tid
on error
set AppleScript’s text item delimiters to def_tid
beep 2
return
end try
copy rec_template to as_rec
repeat with this_field in iCal_rec
set the_offset to (offset of “=” in this_field)
set the_label to text 1 thru (the_offset - 1) of this_field
set the_value to text (the_offset + 1) thru -1 of this_field
if the_label is “FREQ” then
set freq of as_rec to the_value
else if the_label is “BYMONTH” then
set bymonth of as_rec to the_value
else if the_label is “BYDAY” then
set byday of as_rec to the_value
end if
end repeat
end tell
as_rec

Using just the list of labels for this record the result:

{freq:“YEARLY”, bymonth:“1”, byday:“3MO”}

With this AppleScri pt record it is easy to get a value for any field. Then you would need to know the possible values. Again, a list would help. For instance, the “3MO” value in the ‘byday’ field stands for every third Monday. What are all the possible values. You can find them by creating example events and getting the values. This takes a very long time.

Finally, after getting all the values, you would search through every event having recurrences. In these searches, you would search for all events having recurrences that occur on a particular day. This is how you would find every event that occurs on a particular day.

gl,

Note: this line:

set AppleScript’s text item delimiters to {“;”, “=”}

In Jaguar, you can still only set 1 text item delimiter so you don’t need the “=”.

set AppleScript’s text item delimiters to {“;”}

gl,

…my curiosity is more than satisfied! :wink: I can see that even for a skilled expert this is not very workable. If it takes all that work to just start processing one type of recurring event, it would be an incredible project to do a typical real person’s calendar’s worth, with some events recurring yearly, others on the first Thursday of every month, etc. etc… and try to actually generate a list of all events recurring on a particular day. I think I will hold on for TIger and hope that the version of AppleScript that ships with it, along with the Automator, can somehow do the job. But I won’t hold my breath!

Regardless, it’s very interesting to me to see how one would go about parsing the stuff. Thank you!

Jessi

Yes. that’s why if anybody ask you to script events in iCal, then tell them forget it.

gl,

Hi,

Note that if Apple programers made a list of all possible recurrence types and their values, then it might not be so hard to do this. The hard part is trying to make your own list by creating recurrence events and looking at the recurrence.

gl,

…or if Apple programmers added a feature to the iCal scripting dictionary that would just do it for us (get all recurring events for a particular day)!