How to create a repeating event in Automator

applescriptautomatorcalendarical

I would like to programmatically create a repeating event. I'm using Automator and it seems that Automator can't do this, plus I want to pass variables provided by the user into the event creation process so I'm guessing I need to do it in AppleScript instead. Trouble is I haven't been able to find information on how to do that.

How can I create a recurring event in Automator using AppleScript (or really any other way would be worthy of note as well)?

Best Answer

I was unable to get all the way to my ultimate goal of creating repeating calendar events with open file alerts. But, i did at least solve this question of how to create a repeating calendar event in AppleScript, so here it is.

The main issue is that you can't actually create a repeating event. You have to create a static event, then modify that event to repeat. Here's the code that is working for me:

#Event name & description
set title to "event title"
set taskDescription to "The Description"

# which dates to use?
set startDate to date ("07/21/2020")
set endDate to date ("07/21/2020") -- last date to include

# which calendars contain the events?
set thisCalendar to "Automator"

# how many days in between repeats?
set interval to 2

tell application "Calendar"
    tell calendar thisCalendar
        make new event at end with properties {description:taskDescription, summary:title, start date:startDate + 540 * minutes, end date:startDate + 540 * minutes} # creates event at 9am, modify to suit.
        set theEvents to (every event where its start date is equal to startDate + 540 * minutes)
        set recurrence of item 1 of theEvents to "FREQ=DAILY;INTERVAL=" & interval
    end tell
end tell

If you don't have a local calendar called "Automator", then this might give you problems, I'm not sure. Feel free to change the calendar name if needed.