Set alerts on selected Calendar Event(s)

I thought I was doing something simple -- apparently not.

On some important appointments, I like to set the alert for 60,30,15,10 and 5 minutes before the event. it's a lot of clickety-clicks, so I'd like to automate this, and also clearing all the alerts if I change my mind.

I tried searching for AppleScript and JXA scripts that would do this, but it seems that figuring out what is selected in Calendar is a big problem. After exhausting those resources, I turned to ChatGPT, which tried a number of ways to access the events, but nothing worked.

Any suggestions? Is there another clever way to determine which event(s) is selected in Calendar?

Thanks.

Can you explain in a bit more detail about how you want to use this macro? Are you using it as you're creating a new event? Or are you using it after the fact and selecting an existing event then executing the macro?

If it's the latter, I don't have any idea how to help; I've read other things about finding events in Calendar not being a simple task.

But for creating new events, you can use a (relatively) straightforward AppleScript to create a new event, complete with multiple alarms. I have a script that I used ChatGPT to help me write a while back. (You can also do this in Keyboard Maestro with the Create Calendar Event action, but it only supports a single alarm.)

You can fancy this up by gathering input in KM and passing in the vars, etc., but this works to create a new single event with multiple alarms:

tell application "Calendar"
	set calendarName to "Name of Calendar"
	set eventTitle to "title of event"
	set eventStartDate to date "Wednesday, May 29, 2024 at 9:15:00 AM"
	set eventEndDate to date "Wednesday, May 29, 2024 at 10:15:00 AM"
	set eventLocation to "location of event"
	set eventDescription to "description of event"
	
	set theCalendar to calendar calendarName
	
	set newEvent to make new event at end of events of theCalendar with properties {summary:eventTitle, start date:eventStartDate, end date:eventEndDate, location:eventLocation, description:eventDescription}
	
	tell newEvent
		make new display alarm with properties {trigger interval:-60}
		make new display alarm with properties {trigger interval:-30}
		make new display alarm with properties {trigger interval:-15}
		make new display alarm with properties {trigger interval:-10}
		make new sound alarm with properties {trigger interval:-5, sound name:"Basso"}
	end tell
	
	display dialog "New event created."
end tell


Change all the set commands at the top, obviously :).

I'm sure there are better ways to do this; my AppleScript work is about 90% brute force repetition until I find something that works, or give up and ask ChatGPT for help :).

-rob.

1 Like

Thanks much for the help.

Both.

Can you think of a way I could cut an existing event to the clipboard, and then use it to have your script create a new item containing all the previous data with the alarms added?

I'm not sure it's possible, as the cut event wouldn't contain all the necessary data—a quick test showed that all that comes across is the event title and date.

It'd be much easier to add the alarms via AppleScript, but my searching on this subject has shown that it's anywhere from easy to very hard to select a particular event in Calendar (keeping in mind I'm very much an AppleScript neophyte). Here are two sources I found:

Using those two guides, I was able to cobble together a macro that works, assuming the event to be modified is uniquely named. If it's not, well, I don't know what happens :).

This would be much slicker if it could work on the selection in Calendar (i.e. select an event, launch macro, event is modified), but I couldn't figure out how to do that—some AppleScript expert will have to chime in.

But if you have a unique event name, then this macro works, so it's at least a decent proof of concept.

Download Macro(s): Modify Calendar event.kmmacros (11 KB)

Macro screenshot

Macro notes
  • Macros are always disabled when imported into the Keyboard Maestro Editor.
    • The user must ensure the macro is enabled.
    • The user must also ensure the macro's parent macro-group is enabled.
System information
  • macOS 14.5
  • Keyboard Maestro v11.0.3

When run, it gathers a list of calendars, then uses those in an input box to let you set the target event:

Then it goes off, tries to find it, and if found, modifies it to add the specified alarms. If it's not found, you'll get an error notification. Here's my test event after running the macro:

I added a progress dialog just to let you know it's still working, as the AppleScript can take quite a few seconds to run.

Hopefully an AppleScript expert can chime in with better ways of matching the event you want to modify.

-rob.

Thank you for going to all the extra effort.