On my El Capitan system, Calendar’s display isn’t updated when an event’s deleted with AppleScript, but it is updated (including ceasing to display previously deleted events) when AppleScript adds or moves events. The delay before a change becomes visible ” or even if it becomes visible at all ” seems to depend on the total number of events in Calendar at the time, how long it’s been open, and how recently an AppleScript was run on it before the current one!
This version of LouK’s test script cheats by changing the event’s dates to a slot that’s unlikely to be seen and then deleting it. The event remains visible but deleted in the other date slot, but at least it’s gone from the original slot and will be cleared altogether next time an update does take place. I’m afraid it’s more a lesson in workaroundery than in scripting Calendar.
on makeDate(dateDetails)
set aDate to (current date)
set {year:y, month:m, day:d} to aDate
set {year:y, month:m, day:d, hours:h, minutes:min, seconds:s} to dateDetails & {year:y, month:m, day:d, hours:0, minutes:0, seconds:0}
tell aDate to set {its day, its year, its month, its day, its hours, its minutes, its seconds} to {1, y, m, d, h, min, s}
return aDate
end makeDate
-- The compilation of this property depends on the makeDate() handler being above it in the script.
property longAgoDate : makeDate({year:1850, month:January, day:1})
set startDate to makeDate({year:2017, month:April, day:8, hours:14, minutes:15})
copy startDate to endDate
set allDay to false
set alertPrior to 2
set alertPriorUnit to "day"
set duration to 45
return markCalendar(startDate, endDate, duration, alertPrior, alertPriorUnit, allDay)
on markCalendar(startDate, endDate, duration, alertPrior, alertPriorUnit, allDay)
if alertPriorUnit is not "minute" and alertPriorUnit is not "hour" and alertPriorUnit is not "day" then return "Calendar error: alert unit must be \"hour\", \"minute\", or \"day\"."
set alertSeconds to alertPrior * minutes
if alertPriorUnit is "hour" then set alertSeconds to alertPrior * hours
if alertPriorUnit is "day" then set alertSeconds to alertPrior * days
tell application "Calendar"
activate
tell calendar "Home"
set thisEvent to make new event with properties {description:"TEST", summary:"TEST", location:"Event Location", start date:startDate, end date:endDate + duration * minutes, allday event:allDay}
tell thisEvent
--make new display alarm with properties {trigger date:startDate - alertSeconds}
end tell
end tell
display dialog "How's yer father?"
-- Move the event to a date you're unlikely to view and delete it there.
tell thisEvent
set {its start date, its end date} to {longAgoDate, longAgoDate}
delete
end tell
end tell
end markCalendar