1

I'm trying to write a fairly simple AppleScript to automate the process of having Calendar events repeat in bulk. Specifically, I want every event on a given calendar within a given time span to have its repetition set to be biweekly.

This seems like a fairly routine and quick task, but the script below, when run on approximately 30 events in a one-week span, takes about an hour and a half to complete. Moreover, this is only true if I leave the computer untouched while the script runs; if I try to use the laptop simultaneously, the script eventually fails with an error indicating that an Apple Event timed out.

Indeed, iterating through calendar events and accessing or modifying any of their properties seems to take an astronomically long time in AppleScript (for instance, just calling log on the summary of each event). I've tried moving the event fetch to a separate variable and using attributes other than event dates to fetch the events, but nothing seems to improve performance.

What is the reason for this incredible slowness, and what can be done to alleviate it? Or is this simply an inherent part of AppleScript/the macOS Scripting Bridge/Calendar itself?

Here is the script in question:

tell application "Calendar"
    set cal to calendar 1 whose name is "Schedule"
    set theStartDate to date "Sunday, January 27, 2019 at 00:00:00"
    set theEndDate to date "Saturday, February 2, 2019 at 00:00:00"
    repeat with e in (every event of cal whose start date is greater than theStartDate and start date is less than theEndDate)
        set esStartDate to e's start date
        set theWeekday to weekday of esStartDate
        set lower to text 1 thru 2 of (theWeekday as string)
        set upper to do shell script "echo " & lower & " | tr [:lower:] [:upper:]"
        set e's recurrence to "FREQ=WEEKLY;INTERVAL=2;UNTIL=20190602T035959Z;BYDAY=" & upper & ";WKST=SU"
    end repeat
end tell

Looking at the "Replies" console, the script slows both on the initial count every event of calendar id "[ID]" Apple Event as well as on each attempt to modify an event's recurrence.

I'm running macOS Mojave 10.14.2 (Calendar 11.0) on a MacBook Pro early 2015.

2
  • @CJK that's possible, but even just doing log summary of e as text in the loop—without any shell script or additional computation—makes it perform slowly.
    – aaplmath
    Commented Dec 21, 2018 at 14:11
  • @CJK Unfortunately, using a reference to seems to be just as slow as the original approach.
    – aaplmath
    Commented Dec 21, 2018 at 15:32

1 Answer 1

1

Use CalendarLib. CalendarLib is a Script Library that lets you work with Calendar events without using the Calendar app. It is very, very fast:

CalendarLib

CalendarLib is an AppleScript script library for manipulating calendar events without using Calendar.app. It requires OS X 10.9 or later, as well as the BridgePlus script library.

I do not know why Calendar is so slow with AppleScript.

1
  • Unfortunately, CalendarLib doesn't support biweekly event recurrence, so it won't work in this situation.
    – aaplmath
    Commented Mar 27, 2019 at 1:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .