Search code examples
applescripticalendar

Cannot get instance of recurring event in AppleScript Calendar


I have a script that performs actions on events in the next 30 days. I use the following command to get stamp dates for all events between eventStart (today) and eventEnd (today + 30).

set newStamps to get stamp date of (every event of calendar myCal whose start date is greater than eventStart and start date is less than eventEnd and allday event is false)

This returns stamps of events which are not repeated, and it misses stamps from repeated events (from an event with stamp before eventStart but has repeating instances within eventStart and eventEnd)

How can I return all events regardless of whether they are repeated or not?


Solution

  • A repeated event has only one real instance - the very first one. The rest of the events corresponding to this instance are calculated on the fly by the Calendar.app itself, this is a virtual approximation that the script cannot get by requesting the Calendar.app.

    Instead, your script itself should compute what the Calendar.app computes. Knowing the start date of the first instance and the recurrence period, the script should use the normal addition and multiplication operations.

    For example,

    (startDate of N-th instance) = (startDate of 1-st instance) + N* (period of 1-st instance).

    Or,

    (endDate of N-th instance) = (endDate of 1-st instance) + N* (period of 1-st instance)