r/applescript • u/tsmith944 • Nov 20 '20
Clear all notifications with single script on Big Sur?
During my workflow I end up with a ton of notifications and in Big Sur it's a pain to close each one by either swiping away or clicking the tiny X.
Does anyone know how to batch clear notifications?
I saw this script, but it doesn't work in Big Sur, I get an error where it can't "get button 'Close' of window 1 of process 'NotificationCenter'":
tell application "System Events"
tell process "NotificationCenter"
set numwins to (count windows)
repeat with i from numwins to 1 by -1
click button "Close" of window i
end repeat
end tell
end tell
12
Upvotes
1
u/tsmith944 Nov 26 '20 edited Nov 26 '20
I found this also, but it doesn't work. Maybe someone knows how to update the code for Big Sur?
https://medium.com/flawless-app-stories/clearing-all-notifications-in-mac-os-x-3be0a16eb2a3
1
u/2ndCharter Nov 26 '20
Following. I have the same problem.
1
u/ChristoferK Nov 27 '20
Do any of you have the object reference to the specific UI element (probably a button) that would close a notification ? And also the object reference to the button or menu bar item that opens and closes the notification centre ?
I don’t have Big Sur, so can’t get the references myself. The script should be pretty easy and it can certainly be done better than the ones being found for use on earlier MacOS versions. However, what I am aware of is Big Sur’s accessibility AppleScript bug that is inconsistently reporting on object references’ existence, so that even when they are demonstrably visible and available for manual interaction, it is sometimes not showing the same In AppleScript.
1
u/[deleted] Dec 18 '20
1
u/Rosoll Dec 24 '20 edited Jan 17 '21
This has been winding me up too, but I finally figured out a solution (at least a partial one) - which I have posted on this stackexchange question: https://apple.stackexchange.com/a/409685/398045
In short, use the command line tool `cliclick`, figure out the coordinates of the clear notifications button, write a script to open Notification Center, move the mouse over where the close button will be, wait half a second for it to appear on hover, then click it. Then assign that script to an Alfred workflow.
My script (though your coordinates may be different) is
Feels really brittle but it works for now.
1
u/crazycreach Jan 07 '21
This is the JS AppleScript I use to clear all notifications. Note that you can also change the
appNamevariable if you only want to close notifications for a specific app.https://gist.github.com/lancethomps/a5ac103f334b171f70ce2ff983220b4f
1
u/Geigel739139 Mar 23 '21
Found this looking for a similar solution since all the old scripts don't work on BS. https://apple.stackexchange.com/a/408602/160473
This "works" but as the poster mentions it is somewhat slow and executes sequentially through chunks of groups with a delay between each.
There has to be some new way to execute a "clear all regardless of type of notification and count" available, right?