Wednesday, October 23, 2024

The Sad State of Mac Calendar Scripting

AppleScript support with popular Mac calendar apps is surprisingly limited. With Apple Mail, it’s easy to write a script that operates on the selected e-mail messages, and I’ve written many such scripts. I’d like to do this same with calendar events. For example, sometimes I want to make the same change to one of the fields of all the selected events (since there’s no bulk edit inspector). Other times I want to reschedule by shifting all the events by the same amount of time. Sometimes I have a group of past events (e.g. for cooking a Thanksgiving dinner or traveling to a familiar location) and I want to start planning the next iteration by duplicating and shifting them to the future. When traveling east-west, I would like to check that the time zone information is entered consistently.

But this just doesn’t seem to be possible to script. With Apple Calendar and BusyCal, the scripting dictionary does not even let you access the selected calendar events. Readdle Calendars, which recently switched to a subscription, is not scriptable at all. With Fantastical, the dictionary looks promising but mostly doesn’t work:

I contacted support, who said that, despite what the dictionary shows, none of this is supported. All you can do is read (some) of the properties of the selected events and create new events using the parse sentence command. They suggested exporting to ICS, processing the file, and re-importing the ICS. The Export… command exports an entire calendar and so isn’t very useful for this purpose, unless you first copy the events to a temporary calendar. However, you can export individual events via drag and drop.

Some other partial solutions that I found:

Previously:

5 Comments RSS · Twitter · Mastodon


Do you have a script for Mail that blocks certain domains and if you do will Apple Mail accept it and how woul I install it? I know about your spam app but can't afford it.


You can do quite a bit of calendar scripting with Shortcuts. Shortcuts seems to be generally its own special little island within MacOS & iOS, shipping with its own libraries.


@geriatricguy I do not have such a script (since I use SpamSieve’s blocklist), but it should be possible to write a script that modifies Mail’s rules based on the selected message. You can run scripts using the system Script menu.

@Adam I did look into Shortcuts, but I don’t think it provides a way to access the selected events, and it can only find events by date.


Shane Stanley

You can access a lot of EventKit using AppleScriptObjC. I wrote a scripting library, CalendarLib EC, that covers the basics. You can get it here: https://s3.amazonaws.com/latenightsw.com/ShaneLibs/CalendarLib_EC_stuff.zip


@Shane Cool! It looks like the event’s id in Fantastical is the same as the UID with EventKit, so it should be possible to get the selection from the app and then operate on it using CalendarLib EC.

Leave a Comment