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

Hi @vinnie-bob and @peternlewis, after fighting with this for some hours, I think I have a solution/workaround… The quick answer is that does not appear that you create alarms directly in applescript anymore. The long answer, below, is that it should be pretty easy to do it anyway. Thank goodness, as I do a lot of calendar setup at the beginning of each year.

What I figured out is that Calendar is writing a .ics file for you behind the scenes and the alarm information is now included there, not as an element of some applescript accessible object. The .ics format is human readable text and well document across the interwebs, so you shouldn’t have too much trouble creating one – using whatever method/program/language you’d like. Then import with a simple double click.

What I did/have done is created a new event with a ridiculous name, and set up some sample alarms. Behind the scenes, Calendar has created an ics file in ~/Library/Calendars//Events. Then it was just a quick search for the ridiculous event name in finder (you may need to include system files) and opening it in a text editor to see a sample.

Alarms created by Calendar look like this:
BEGIN:VALARM
X-WR-ALARMUID:7870A085-C2CD-4D06-89E3-42018AF35670
UID:7870A085-C2CD-4D06-89E3-42018AF35670
TRIGGER:-PT5M
ATTACH;VALUE=URI:Chord
ACTION:AUDIO
END:VALARM

but when you write them into a file for importing you don’t need the two UID lines, Calendar will create them for you. Also note that .ics does not store a calendar name, you select where things go when you import.

A single .ics file will happily hold multiple events:
BEGIN:VCALENDAR
BEGIN:VEVENT
…
END:VEVENT
BEGIN:VEVENT
…
END:VEVENT
END:VCALENDAR
Similarly, a single VEVENT can contain multiple VALARMs

There doesn’t seem to be a whole lot of required field for a valid .ics and to get Calendar to create your event, but I haven’t figured out what the minimum is. Certainly you need DTEND DESCRIPTION DTSTART and probably want SUMMARY. It does populate/take care of all the would-be-messy stuff that you will see if you create a sample the way I did: UIDs, SERVERFILENAMEs, ETAGs. All that you can just throw out in an .ics you create for import.

For the moment I will probably just modify my old CVStoCalendar applescripts to write an .ics, but I don’t have any code written to share yet. Longterm I will likely move them to some other language.

Obviously it has been a number of months since this thread was active, but I hope those on it will get some sort of notification, I will try to remember to check back in the near future to see if anyone has any questions about what I’ve written.

1 Like