r/applescript • • 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

24 comments sorted by

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/crazycreach Jan 07 '21

This is the JS AppleScript I use to clear all notifications. Note that you can also change the appName variable if you only want to close notifications for a specific app.

https://gist.github.com/lancethomps/a5ac103f334b171f70ce2ff983220b4f

1

u/tsmith944 Jan 07 '21

Does this work on Big Sur? Can you advise how you run this? I tried in Script Editor, but I'm not sure how to run a .js apparently. This sounds promising, thank you!

1

u/crazycreach Jan 08 '21

Yea, it is meant for Big Sur. Open Automator, create a new document, choose Application for your type, add the "Run JavaScript" action, and paste the code there. You can then save the Application and any time you open it, it will run the code to close your notifications. I use BetterTouchTool to map it to a keyboard shortcut.

1

u/tsmith944 Jan 08 '21

That's perfect! Thank you!

→ More replies (10)

1

u/[deleted] Dec 18 '20

[removed] — view removed comment

1

u/tsmith944 Dec 18 '20

I’m still hoping someone can figure this out, even a wonky workaround is fine. It’s really annoying and I sometimes have notifications that line the entire right side of my screen.