turn off alerts for all events in a calendar

So I have a calendar with a bunch of repeating events. When I created them, I left the alerts to the default, which is to alert five minutes before the event start time.

Turning off alerts one by one is a pain, so I tried to write a script to do so, but it doesn’t work. The alerts are still on in the calendar.

Here’s what I wrote:


tell application "Calendar"
	tell calendar "CNN"
		repeat with i from 1 to count of events
			set trigger interval of event i to 0
			save
		end repeat
	end tell
end tell

Hi,

  1. trigger interval is property of alarms, not of events
  2. I save always Calendar.app’s state, and don’t know if it works with certain calendar as well. So I would put save command in the tell application block.
  3. Most likely, the repeat loop no needed
  4. I can’t test the script bellow, but I think it should work:

tell application "Calendar"
	tell calendar "CNN"
		set trigger interval of every display alarm of every event to 0
		set trigger interval of every mail alarm of every event to 0
		set trigger interval of every open file alarm of every event to 0
		set trigger interval of every sound alarm of every event to 0
	end tell
	save
end tell

The meeting whose alarm I wanted to turn off was a display alarm.

when I ran this code:

properties of display alarm of theMeeting

I got the result:

{{class:open file alarm, trigger interval:-10, trigger date:missing value}}

So I ran this code:

set trigger interval of display alarm of theMeeting to 0

And the result was that the alarm now goes off at the meeting start time.

Is there anyway I can set the alert to “None” like I can do with the Calendar interface?

Hi. ‘None’ is nonexistent, so you’d delete the offending alarm(s).

tell application "Calendar" to tell calendar "CNN"
	tell events 
	 delete sound alarms
	 delete display alarms
	 end
end tell

Ah, thank you. The solution is simpler than I thought it would be.

I just tried deleting a sound alarm with the delete keyword.


tell application "Calendar" to tell calendar "CNN"
	tell events 
	 delete sound alarms
	 delete display alarms
	 end
end tell

I got this error though:

Calendar got an error: AppleEvent handler failed.

This is an application bug.

The following script is somewhat slow, but at least it works better (for removing alerts) than Apple does. And better than manually deleting alerts. Perhaps experts (like Nigel Garvey) will not be too lazy to improve its speed. I added a progess bar to make it less boring.


use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions

tell application "Calendar" to tell calendar "CNN"
	set theEvents to get events
	set countEvents to count theEvents
end tell
if countEvents = 0 then return

set progress total steps to countEvents

repeat with i from 1 to countEvents
	set progress description to "Process Event " & i & " of " & countEvents
	
	tell application "Calendar" to tell calendar "CNN"
		
		set anEvent to item i of theEvents
		tell anEvent
			set |allday event| to allday event
			set |start date| to start date
			set |end date| to end date
			set |url| to url
			set |location| to location
			set |recurrence| to recurrence
			set |description| to description
			set |excluded dates| to excluded dates
			set |stamp date| to stamp date
			set |summary| to summary
		end tell
		
		delete anEvent
		
		set newEvent to (make new event at end of events with properties {allday event:|allday event|, start date:|start date|, end date:|end date|})
		tell newEvent
			if not (|url| is missing value) then set url to |url|
			if not (|location| is missing value) then set location to |location|
			if not (|recurrence| is missing value) then set recurrence to |recurrence|
			if not (|description| is missing value) then set description to |description|
			if not (|summary| is missing value) then set summary to |summary|
			if not (|excluded dates| is missing value) then set excluded dates to |excluded dates|
			if not (|stamp date| is missing value) then set stamp date to |stamp date|
		end tell
		
	end tell
	
	set progress completed steps to i
end repeat

Thank you. I will test this out.

I would like to clarify something: full blocking of alerts in Calendar.app is not possible. You can verify this by manually setting the alerts to None. A few seconds after your setting, Calendar.app automatically adds a default value: display alarm “Alert 30 minutes before the start”.

My script just does the same thing: it removes the custom alerts, and Calendar.app automatically adds the default value. If that’s enough for you, here’s a slightly more efficient script:


tell application "Calendar"
	set theCalendar to calendar "CNN"
	tell theCalendar to set theEvents to events
end tell
if theEvents is {} then return

set countEvents to count theEvents
set progress total steps to countEvents
set i to 0
repeat with anEvent in theEvents
	set i to i + 1
	set progress description to "Process Event " & i & " of " & countEvents
	tell application "Calendar" to tell theCalendar
		tell anEvent to set {|allday event|, |start date|, |end date|, |url|, |location|, |recurrence|, |description|, |summary|, |excluded dates|, |stamp date|} to {allday event, start date, end date, url, location, recurrence, description, summary, excluded dates, stamp date}
		tell (make new event at end of events with properties {allday event:|allday event|, start date:|start date|, end date:|end date|, stamp date:|stamp date|, description:|description|, summary:|summary|})
			if not (|url| is missing value) then set url to |url|
			if not (|location| is missing value) then set location to |location|
			if not (|recurrence| is missing value) then
				set recurrence to |recurrence|
				set excluded dates to |excluded dates|
			end if
		end tell
		delete anEvent
	end tell
	set progress completed steps to i
end repeat

The first iteration of your script worked. The second iteration had an error about trying to convert a missing value to text.

Parsing through your code, I see that it duplicates the event that doesn’t have any alerts and deletes the old event. It makes sense now.

What is the purpose of putting your variables in between the two ||s? (|variableName|)

For the first script, I added a choice so the user can select the calendar from a list:


use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions

tell application "Calendar"
	set calendarList to name of calendars
	set calendarName to choose from list calendarList
	set calendarName to item 1 of calendarName
end tell


tell application "Calendar" to tell calendar calendarName
	set theEvents to get events
	set countEvents to count theEvents
end tell
if countEvents = 0 then return

set progress total steps to countEvents

repeat with i from 1 to countEvents
	set progress description to "Process Event " & i & " of " & countEvents
	
	tell application "Calendar" to tell calendar calendarName
		
		set anEvent to item i of theEvents
		tell anEvent
			set |allday event| to allday event
			set |start date| to start date
			set |end date| to end date
			set |url| to url
			set |location| to location
			set |recurrence| to recurrence
			set |description| to description
			set |excluded dates| to excluded dates
			set |stamp date| to stamp date
			set |summary| to summary
		end tell
		
		delete anEvent
		
		set newEvent to (make new event at end of events with properties {allday event:|allday event|, start date:|start date|, end date:|end date|})
		tell newEvent
			if not (|url| is missing value) then set url to |url|
			if not (|location| is missing value) then set location to |location|
			if not (|recurrence| is missing value) then set recurrence to |recurrence|
			if not (|description| is missing value) then set description to |description|
			if not (|summary| is missing value) then set summary to |summary|
			if not (|excluded dates| is missing value) then set excluded dates to |excluded dates|
			if not (|stamp date| is missing value) then set stamp date to |stamp date|
		end tell
		
	end tell
	
	set progress completed steps to i
end repeat

You should read the additional post #9 to understand me better. It seems, Calendar.app creates automatically default display alarm when you delete all alarms. So, my scripts make sense only for deleting the additional alarms (that is, user created alarms). As I sad, in the post #9, at least 1 alarm should exist for each event. It is the behaviour of Calendar.app, and we can’t do something with it.

The purpose of putting your variables in between the two pipes is: you say to AppleScript that it is the name of user created variable and not the property of some event of some calendar of Calendar.app. And, using pipes, you can give to user created variables names with spaces.

Thank you for the clarification. The pipes thing will come in handy.

The Calendar app on my system does not exhibit the behavior you are describing about automatically recreating alerts. Once I delete an alarm manually or with your script, no alarms automatically pop up.

Regardless, your script will save me time in the future when I want to mass delete alerts. Thank you.

I am about to run one of the solutions suggested in this thread but before I do I would like to list all events in a certain calender that do and do not have an alarm (Background: I used a web service to add events to a calendar and for a while it added undesired alarms. However, I think I might manually have added a couple of alarms that I want to take note of before deleting everything.)

Bonus points if the list of events with/without alarms also lists the trigger interval as well as if the event is all day or not.

Thank you all.