More Calendar hijinx in Catalina

I have a script to calculate Lawn Chemical application which I use once a year. Last year in Mojave, everything worked fine. Now on new laptop (16" MBPro) and using Catalina. Having no joy trying to set a new event using Applescript below. Can anyone reproduce? Suggestions?

set datelist to {date "Saturday, April 11, 2020 at 9:00:00 AM"}
tell application "Calendar"
	activate
	set mylist to the name of every calendar as list -- get names of all calendars
	-- use list for user to choose what calendar events should be added to
	set tCalendar to choose from list mylist with title "Calendar Selector" with prompt "Which calendar do you want to add these events to?" OK button name "OK" cancel button name "Cancel" without multiple selections allowed and empty selection allowed
	set y to 1
	repeat with x in datelist
		tell calendar (item 1 of tCalendar)
			set theEvent to make event at end with properties {allday event:false, description:"Do the lawn treatment!", start date:(current date), end date:((current date) + 1 * hours), summary:"Apply lawn treatment"}
			tell theEvent to make new display alarm at end with properties {trigger interval:-15}
			set y to y + 1
		end tell
	end repeat
end tell

fails at “set theEvent…” line with this:

Calendar got an error: Failed to save event [Apply lawn treatment] with error [{
CalAlarmUID = “ACA24D0C-45D6-4826-83D2-DC95143FFCFD”;
CalCalendarItemUID = “7E7FE972-DAB1-44C2-975B-3718B159D111”;
CalCalendarUID = “32E33082-0A58-489E-B4FC-2A3803909226”;
CalManagedObjectType = CalManagedAlarm;
NSLocalizedDescription = “action is a required value.”;
NSValidationErrorKey = action;
NSValidationErrorObject = “<CalManagedAlarm: 0x600003735360> (entity: Alarm; id: 0xa81702f2a210db x-coredata://4C493856-A93D-458D-8CEE-6B00AD3D6217/Alarm/p7402; data: {\n absoluteTrigger = nil;\n acknowledged = nil;\n action = nil;\n bookmark = nil;\n calendar = nil;\n defaultAlarmByReference = nil;\n defaultAlarmSetEventAllDay = nil;\n defaultAlarmSetEventTimed = nil;\n deleteSyncRecord = nil;\n emailAddress = nil;\n isDefaultAlarm = 0;\n isTimeToLeaveAlarm = nil;\n itemCustomAlarm = nil;\n itemLocalDefaultAlarm = nil;\n itemServerDefaultAlarm = nil;\n location = nil;\n message = nil;\n notRelativeToTravel = 0;\n omitSyncRecord = nil;\n order = 0;\n parentAlarmsByValue = nil;\n proximity = nil;\n relatedTo = nil;\n relativeTrigger = “-900”;\n sound = nil;\n subject = nil;\n timeToLeaveDate = nil;\n timeToLeaveEstimatedTravelTime = nil;\n timeToLeaveTrafficDensityString = nil;\n timeToLeaveTransportType = nil;\n uid = nil;\n unrecognizedICSProperties = nil;\n url = nil;\n urlString = nil;\n})”;
}]

OK, this is the type of ugliness you should not have to do in a work around. I removed some of the properties in the line which sets the new Event, and then the line right after that which set a display alarm was triggering an error (seems you need a trigger date now too). Of interest, the event seemed to get written to Calendar and appeared to have a display alarm set at 15 minutes before even as applescript reported an error, so just put a ‘try’ handler in and ignore the error. Fantastic ???

I need to convert this to use Shane’s Calendar library, methinks……

set datelist to {date "Saturday, April 11, 2020 at 9:00:00 AM"}
tell application "Calendar"
	activate
	set mylist to the name of every calendar as list -- get names of all calendars
	-- use list for user to choose what calendar events should be added to
	set tCalendar to choose from list mylist with title "Calendar Selector" with prompt "Which calendar do you want to add these events to?" OK button name "OK" cancel button name "Cancel" without multiple selections allowed and empty selection allowed
	set y to 1
	repeat with x in datelist
		tell calendar (item 1 of tCalendar)
			set theEvent to make new event at end with properties {start date:(current date), end date:(current date) + 1 * hours, summary:"Apply lawn treatment"}
			try
				tell theEvent to make display alarm at end with properties {trigger date:item 1 of datelist, trigger interval:-15}
			on error errMsg number errNum
				-- do nothing, ignore error as the script seems to work and sets alarm
			end try
			set y to y + 1
		end tell
	end repeat
end tell

So did you manage to get this to add actual alarms? My attempts have all failed to actually add any alarms.

Adding the try just hides the error, but still doesn’t add an alarm for me.

Sorry for the late reply, Peter but I was out of town.

No, I was not able to get it to add an alarm for a specific time, that is why I just skipped that line. But since I was just using this to remind me to do lawn fertilizer, the timing wasn’t important and just having the default alarm provided by adding an event sometime during the day was all that I needed.

1 Like