0

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)?

15
  • In theory, this can be done by setting a calendar alarm that triggers an Automator workflow to run. But I'd personally due it by way of launchd. – CJK Jul 18 '20 at 4:57
  • OK so basically it can’t be done… There is no actual way to create a genuine repeating event like you would manually, you have to fake it with some sort of scheduled action? What a shame. – JVC Jul 18 '20 at 13:21
  • Perhaps I misspoke. The “calendar alarm” is a builtin function of Automator, which you should see when you go to create a new workflow, for which one of the options is called ”Calendar Alarm”. The description provided when selected states ”Calendar Alarms are workflows that are run when triggered by an event in Calendar. They receive no input.” What is it you’re wanting to do ? Perhaps I am misunderstanding what you mean by “repeating event” ? – CJK Jul 19 '20 at 8:28
  • I just want to programmatically (as in, via AppleScript) create a repeating calendar alert that triggers an application. – JVC Jul 19 '20 at 13:11
  • 1
    Excellent! You'll have to show me how it's done. – CJK Jul 19 '20 at 17:04
0

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.

2
  • 1
    If the target calendar does not exist, it will error out. – user3439894 Jul 19 '20 at 18:24
  • Yep, exactly why I mentioned that they may need to change the calendar name. – JVC Jul 19 '20 at 18:39

You must log in to answer this question.

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