Saturday, September 24, 2022

#1 2021-01-16 01:14:12 pm

wayland
Member
From:: Nha Trang
Registered: 2020-05-13
Posts: 76

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:

Applescript:


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

Offline

 

#2 2021-01-17 07:25:49 am

KniazidisR
Member
From:: Greece
Registered: 2019-03-03
Posts: 2522

Re: turn off alerts for all events in a calendar

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:

Applescript:


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

Last edited by KniazidisR (2021-01-17 07:27:39 am)


Model: MacBook Pro
OS X: Catalina 10.15.7
Web Browser: Safari 14.1
Ram: 4 GB

Offline

 

#3 2021-01-25 01:23:21 pm

wayland
Member
From:: Nha Trang
Registered: 2020-05-13
Posts: 76

Re: turn off alerts for all events in a calendar

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?

Offline

 

#4 2021-01-25 07:11:37 pm

Marc Anthony
Member
From:: Dallas, TX
Registered: 2006-04-27
Posts: 1090

Re: turn off alerts for all events in a calendar

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

Applescript:

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

Offline

 

#5 2021-01-29 02:34:59 am

wayland
Member
From:: Nha Trang
Registered: 2020-05-13
Posts: 76

Re: turn off alerts for all events in a calendar

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

Offline

 

#6 2021-02-07 01:49:11 pm

wayland
Member
From:: Nha Trang
Registered: 2020-05-13
Posts: 76

Re: turn off alerts for all events in a calendar

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

Applescript:


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.

Offline

 

#7 2021-02-09 01:58:01 am

KniazidisR
Member
From:: Greece
Registered: 2019-03-03
Posts: 2522

Re: turn off alerts for all events in a calendar

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.

Applescript:


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

Last edited by KniazidisR (2021-02-09 02:10:16 am)


Model: MacBook Pro
OS X: Catalina 10.15.7
Web Browser: Safari 14.1
Ram: 4 GB

Offline

 

#8 2021-02-12 05:13:12 am

wayland
Member
From:: Nha Trang
Registered: 2020-05-13
Posts: 76

Re: turn off alerts for all events in a calendar

Thank you. I will test this out.

Offline

 

#9 2021-02-13 01:47:46 pm

KniazidisR
Member
From:: Greece
Registered: 2019-03-03
Posts: 2522

Re: turn off alerts for all events in a calendar

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:

Applescript:


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

Last edited by KniazidisR (2021-02-14 12:28:46 am)


Model: MacBook Pro
OS X: Catalina 10.15.7
Web Browser: Safari 14.1
Ram: 4 GB

Offline

 

#10 2021-02-14 02:53:09 pm

wayland
Member
From:: Nha Trang
Registered: 2020-05-13
Posts: 76

Re: turn off alerts for all events in a calendar

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:

Applescript:


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

Offline

 

#11 2021-02-15 02:58:30 am

KniazidisR
Member
From:: Greece
Registered: 2019-03-03
Posts: 2522

Re: turn off alerts for all events in a calendar

wayland wrote:

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|)


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.

Last edited by KniazidisR (2021-02-15 03:08:43 am)


Model: MacBook Pro
OS X: Catalina 10.15.7
Web Browser: Safari 14.1
Ram: 4 GB

Offline

 

#12 2021-02-18 06:16:34 am

wayland
Member
From:: Nha Trang
Registered: 2020-05-13
Posts: 76

Re: turn off alerts for all events in a calendar

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.

Offline

 

#13 2022-05-24 04:07:05 am

lagr
Member
Registered: 2022-04-09
Posts: 5

Re: turn off alerts for all events in a calendar

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.

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)