Here's how to create an event with AppleScript in the Calendar App on macOS. This tutorial contains a simple code sample and a more advanced example.

Besides offering great performance and usability by being a native application, Calendar also has a very powerful feature by being able to interact with AppleScript.

While you can perform various operations involving events and calendars, the most useful one to automate, I think, is making an event.

Let's have a look at a simple example so you can better understand the AppleScript code:

                      tell                          application                        "Calendar"                      tell                          calendar                        "Your Calendar Name"                                    make              new              event              at            end            with properties            {summary:"Event Name",            start date:(              current date            ),            end date:((              current date            ) + (1 *            hours))}                      end tell                                end tell                  

So what does this code do? The first line is self-explanatory, I think. In the second one you have to choose the calendar name to which the event should be added. The third line is where the magic happens. The begin is easy to understand. The event has three properties in this example:

  1. The first, `summary`, is where you specify the name of the event.
  2. Then comes the `start date` which sets the time when the event should start. I used the `current date` command which gets the current date and time when the script is executed.
  3. Finally, for the `end date` I simply added 1 hour to the current date and time to replicate the default duration of an event. Instead of hours you can put minutes or even seconds.

Important note: You'll probably have to give Script Editor permission to access your calendars, in System Preferences.

But this script on its own isn't particularly useful except for learning the syntax of how to create a calendar event programmatically. To make something that can easily be used every day, we need to write a bit more code. Not a lot, but a bit more.

How I Add Calendar Events With AppleScript on My Mac

There are few ways to add a new calendar event, but all of them require you to choose the time when you want the event to start. Even the "Create Quick Event" function.

This is a problem if you use Calendar to set reminders for the very near future. Let's say you just remembered you have to write an email, but you're doing something else right now. To not interrupt yourself, it would be nice to add a reminder in 15 minutes for you to write that email. But what you need to do at the moment is look at the clock, add 15 minutes to the current time and use the "Create Quick Event" dialog to set a reminder for that specific time.

This is the solution I came up with:

And here is the code to achieve this:

                                    display dialog                        "Create Quick Event"            default answer            ""            buttons            {"Cancel", "Add Event"}            default button            2                                set            eventText            to            (text returned            of            result)                      set            eventName            to                          do shell script                        "echo " &            eventText            & " | awk -F ' in ' '{print $1}'"                      set            eventDelay            to                          do shell script                        "echo " &            eventText            & " | awk -F ' in ' '{print $2}'"                                tell                          application                        "Calendar"                      tell                          calendar                        "Reminders"                      set            theCurrentDate            to                          current date                                            set            eventStart            to            theCurrentDate            +            eventDelay            *            minutes                                set            eventEnd            to            eventStart            + 60 *            minutes                                make new              event                        at            end            with properties            {summary:eventName,            start date:eventStart,            end date:eventEnd}                      end tell                                end tell                  

Let me offer a quick explanation of what this script does:

  1. The first line creates a dialog window with a text field and two buttons.
  2. The following section processes the text written in the aforementioned text field. For everything to work right, the text should match this pattern: it should start with the event name followed by the word "in" and it should end with the number of minutes (starting from now) when you want to be reminded. For example: "Send email in 15".
  3. The last part was explained in the simple example.

Tip: For every day use, run this AppleScript code from Automator and save it as an application. This way it will not ask you for Calendar access every time you run the app.

Run Calendar AppleScript in Automator

If this doesn't look very appealing to you, the same functionality and much, much more can be achieved by using Fantastical. I used the Mac version and it's very nice.