macOS Calendar - Event with Multiple Alerts

Hi,

Goal

  • to create a macOS calendar event - WORKING
  • with multiple alerts

Issue:

Any help would be appreciated

set targetDate to current date

set year of targetDate to 2023
set month of targetDate to 5
set day of targetDate to 24

tell application "Calendar"
	tell calendar "My Calendar"
		set newEvent to make new event at end with properties {summary:"Event Name", start date:targetDate, end date:(targetDate + (1 * hours)), description:"test"}
		set allday event of newEvent to true
		tell newEvent
			-- Add a message with sound alarm
			-- ERROR Calendar got an error: Can’t make {trigger interval:1 * days, sound name:"Sosumi"} into type properties of display alarm.
			make new display alarm at end of display alarms with properties {trigger interval:-1 * days, sound name:"Sosumi"}
			
			-- Add a message with sound alarm
			make new sound alarm at end of sound alarms with properties {trigger interval:1 * days, sound name:"Sosumi"}
			
			
		end tell
	end tell
end tell

The reason you can’t create a display alarm is simple. Such an object does not exist in recent versions of Calendars.

You can verify this by trying to add it manually. When trying to create a Custom alarm, 3 options are provided: sound alarm, mail alarm, open file alarm. display alarm remained as an anachronism, only in the application dictionary.

Check Calendar’s scripting dictionary:

  1. Display alarm does not have a ‘sound name’ property. The script will compile, but will error at runtime.

  2. Trigger intervals are specified in minutes. -1 * days is -86400 (seconds), but this will be interpreted by Calendar as minutes (ie 60 days before). Try it with -1 * days / 60.

Even with removing the ‘sound name’ property I still get an error.

make new display alarm at end of display alarms with properties {trigger interval:-1 * days}

Calendar got an error: Failed to save event [Event Name] with error [{
CalAlarmUID = “FF5106AA-1D48-4E97-8FF8-D65AFCAA6985”;
CalCalendarItemUID = “91B8EE20-0D26-488B-8403-91CBCDB161D8”;
CalCalendarUID = “577A5424-15A7-40C2-A3F7-D8F8456078CF”;
CalManagedObjectType = CalManagedAlarm;
NSLocalizedDescription = “action is a required value.”;
NSValidationErrorKey = action;
NSValidationErrorObject = “<CalManagedAlarm: 0x60000261c280> (entity: Alarm; id: 0x5e63f818a84ddcff x-coredata://DC6E470B-02AC-4F54-873E-E7EEB6EB2541/Alarm/p9283; data: )”;
NSValidationErrorValue = “”;
}]

Unsure how to fix it, any help would be appreciated.

  1. Display alarms creating is not available in the recent Calendar.app versions. (see my post 2 of current topic).

  2. Trigger intervals you should specify in minute units. To specify 60 minutes need -1 * days / 60, because -1 * days returns integer of seconds. Or, specify integer (60).

  3. To add custom alarms, you need allday event:false instead of allday event:true

  4. You can add multiple sound alarms.
     

set startDate to current date
tell startDate to set {year, its month, day} to {2023, 5, 24}
set endDate to startDate + days

tell application "Calendar" to tell calendar "MyNewCalendar"
	set newEvent to make new event at end with properties {summary:"Event Name", allday event:false, start date:startDate, end date:endDate, description:"test"}
	tell newEvent
		-- creating display alarms not available
		-- create 2 custom sound alarms
		make new sound alarm at end of sound alarms with properties {trigger interval:-60, sound name:"Sosumi"}
		make new sound alarm at end of sound alarms with properties {trigger interval:60, sound name:"Sosumi"}
	end tell
end tell

 
NOTE: when you create new event without adding custom alarms, the Calendar.app adds default sound alarm with trigger interval -30 minutes.

Display alarm compiles, runs and creates a basic alarm for me in Ventura 13.4. Looks like it’s been fixed.

Edit: Or sort of - the alarm runs on my iPhone but not on my Mac.

Edit again: Calendar notifications were turned off in System Settings. :blush: When I turned them on, the alarm was displayed on my Mac.

I’ll just add information for Catalina v10.15.7 users like mine.

I still have events with display alarms created in Calendar.app when I was on older OS. So, Calendar.app of Catalina recognizes them and they work, but this version (Version 11.0 (2760.4.1)) of the application does not have the ability to create new display alarms.

Unfortunately, my hardware does not allow updates further Catalina

it works. Thanks a lot it was a head scratcher.