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:
my closeNotifications()
on closeNotifications()
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
try
click button 1 of this_item
on error
my closeNotifications()
end try
end repeat
end tell
end closeNotifications
Instead of adding it as an actual button to BTT, I added it as an AppleScript widget to make the button appear only when there are notifications - otherwise it is hidden to save space. Like this:
tell application "System Events"
if exists (window 1 of process "Notification Center") then return "Dismiss All"
end tell
return ""
I also have it set to only show the icon, which hides the “Dismiss All”. BTT is crazy powerful, particularly when it comes to the touchbar.
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.
Same here; I misinterpreted. I never get more than a few notifications, and most fade away in just a few seconds, so this might not be all that useful to me.
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!