I still need persistent notifications on my MacBook Pro, but boy is it annoying when I open my mac after 12+ hours, and I’m greeted to a wall on the right side of my screen of over 20 notifications. And in 2018, it’s crazy that there is still not a “Dismiss All Notifications” command built into the OS. So, click, click, click, click, seemingly forever.
I finally found a great applescript to do the trick. Using Better Touch Tool, I’ve mapped it to Alt-Cmd D, and also added it as a button to my Touch Bar. I highly, highly recommend it. I wish I could take credit for writing the script. I don’t even know if it’s optimized for this use, but it’s been great:
tell application "System Events" to tell process "Notification Center"
set theWindows to every window
repeat with i from 1 to number of items in theWindows
set this_item to item i of theWindows
click button 1 of this_item
I just tried running it in Script Editor with similar results to @rob. In my case, nothing happens with the notifications showing or not showing. Oddly, a very short click on the “run” button in the Script Editor when the window is showing shows this result:
button 1 of window “Notification Center” of application process “NotificationCenter” of application “System Events”
To clarify, the script dismisses Notifications (separate windows with two buttons each), NOT the items listed in Notification Center. In testing, if I open Notification Center without any Notifications present and fire the script before it auto-closes, it will launch Notification Center settings. If Notifications are present, it works as expected.
Okay, now you got me. So, what did you do? I’m guessing under BTT-TouchBar, you added a Widget.
“Run Apple Script and Show Return Value?” is the apple script above separate from the script that I posted? (Is the widget referring to a separate script?) Or, is it all one long apple script, with your code at the top?
Evan, I finally have a minute to get back to this. It took me a minute to figure out how to set it up, but I finally got it. the Applescript of the widget is returning whether the button exists or not, and then i’m putting the applescript to execute the dismiss all under the Predefined Action if that button is touched. Very clever. THANKS!