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,