29

I have notifications in the OSX Notification Center, as for most of my apps I am using the setting, "Show in Notification Centre: 10 Recent Items" This is a good setting but rather than have a very full Notification Center, I would still like to clear it from time to time with 1 click.

I am using Yosemite 10.10.3

12 Answers 12

18
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

Copy and Paste the above code into AppleScript Editor Enable Script Editor in Accessibility

System Preferences enter image description here

4
  • Fantastic solution! I mapped your script to a keyboard shortcut in BTT: boastr.net
    – cody.codes
    Sep 28, 2019 at 15:30
  • How do you invoke this? Jan 16, 2020 at 20:28
  • 3
    This doesn't work on Big Sur: System Events got an error: Can’t get button "Close" of window 1 of process "NotificationCenter". (-1728)
    – HappyFace
    Mar 13, 2021 at 11:47
  • 1
    Is this still working in big sur. I've tried running and modified it and it's not closing notifs Aug 19, 2021 at 22:47
7

Another option, which uses Keyboard Maestro to run an Applescript is detailed here: http://genuinecuriosity.com/unnotify

I have it mapped so that I hit Command Option 0 to clear all open alert dialogs.

Basically, I have created an Applescript to click the first button on all open alerts (typically Close), and does that until all alerts are cleared. You can use the Applescript directly through Keyboard Maestro (as described in my article), or you can create a Service with Automator (this is a little more finicky due to Accessibility permissions requirements).

The full Applescript is included in the article, along with a screen grab showing the setup in Keyboard Maestro. Script employed in Keyboard Maestro

2
  • It's helpful if you briefly summarize the linked reference as links can go stale in the future.
    – Allan
    Jun 6, 2016 at 9:28
  • Brilliant thank you! You can copy paste the script into Alfred as well. Oct 20, 2017 at 5:40
6

I know this was originally for Yosemite, and I'm not sure the answer there, but given the question is 3 years old, and I just found it while looking for the same thing with Mojave, I thought I'd mention the answer I found.

enter image description here

on the very right of the menu bar, click on the 3 lines, this brings up a window with Today / Notifications tabs. If you select the Notifications tab, you can click the X to the right of Today to clear all the notifications for a given day. a few clicks and you'll have all the old ones cleared.

4
  • Would this clear a backlog of notifications? Dec 16, 2018 at 22:26
  • yes, that's the idea. I use it periodically to clear out a lot of notifications.
    – Kem Mason
    Dec 18, 2018 at 20:24
  • If u wanna stay away from scripts this is the answer! Mar 27, 2019 at 13:41
  • This cleared the day's notifications from Notification center, but it didn't dismiss "Alerts", (the persistent window type of Notifications that can be chosen in System Prefs -> Notifications). The short applescript solution by "@software is fun" did clear those. The question is about Notifications, but I wanted to note that distinction here. Mar 30, 2020 at 12:39
5

I don't know a way to clear every notification with a single button, however you can clear all of one app's notifications by moving your mouse to the right of the app's header and clicking the small x button that appears there.

To clear them all, I simply move the mouse to the topmost app's x button and rapidly click which removes all of the notifications relatively quickly.

4
  • 1
    thanks, that is what I do. Clicking the small x at the top of each notification section for 20 apps, is definitely not fast in my book. Not sure why you popped reply as an answer.
    – sea
    May 4, 2015 at 18:18
  • @sea Haven't got comments yet
    – Sébastien
    May 4, 2015 at 18:50
  • 1
    I don't see any "small x" on El Capitan 10.11.1
    – Meekohi
    Nov 3, 2015 at 14:35
  • 2
    You can close by day, if you hover over the day header line.
    – Tetsujin
    Apr 7, 2016 at 14:36
4

I ended up creating an Automator script to do this and mapping it to a global hotkey.

on run {input, parameters}
    tell application "System Events"
        tell process "Notification Center"
            set theWindows to every window
            repeat with i from 0 to number of items in theWindows
                try
                    set this_item to item ((number of items in theWindows) - i) of theWindows
                    click button 1 of this_item
                on error
                    -- nothing
                end try
            end repeat
        end tell
    end tell
end run
3

Here's solution that requires the Terminal, but it works with Big Sur. This is useful in particular if you have dozens of notifications from the Finder that can't be quickly closed using other approaches.

From Terminal:

ps -e | grep /NotificationCenter | grep app | awk '{print $1}' | xargs kill -9

This is similar to Joey's answer, except it does it all in one command. ps -e gets a list of running processes. The grep filters the list to those containing /NotificationCenter. This list still has too many items because the grep command itself ends up finding itself. We exclude it by running another grep on the output of that list. The awk command prints the first column, which is the process id that we need to restart. Xargs takes the output of the previous command and feeds it to its arguments, namely, "kill -9" which is the unix command to exit a process.

The practical outcome is that the NotificationCenter.app is stopped. Launchd (the system process that launches other system processes) notices that Notification Center went away, and reinitiates it. When it comes back, all the messages in its queue are lost and your notifications are cleared.

4
  • The notifications are very much not lost on macOS 11.2.1.
    – HappyFace
    Oct 4, 2021 at 9:18
  • Interesting. There is also a UserNotificationCenter. Does the tip work for you if you try: ps -e | grep /UserNotificationCenter | grep app | awk '{print $1}' | xargs kill -9
    – Khan
    Oct 5, 2021 at 14:31
  • No, that won't even hide the notification for a second (which the previous version did).
    – HappyFace
    Oct 5, 2021 at 18:20
  • 1
    It's now 2022 and I was looking for an update to this for Monterey - specifically because Mac Mail doesn't include a "Clear All" button. Anyhow, I pasted the above command into Terminal, but when Notification Center relaunches, it displays the same alerts again.
    – Tony
    Feb 9 at 15:41
2

The small X in El Capitan is in the notification window. Open the Notification pane by sliding in from the right on the mouse or clicking on the notification center icon in the upper left corner. Each application's notifications are grouped together and there is a little X on the right side of each application's header. Click that X and the notifications all go away.

2

This SIMBL app does the trick nicely. chuckhendo/NotificationClear: SIMBL bundle to add a "Clear All" button to Notification (https://github.com/chuckhendo/NotificationClear)

Just install it using mySIMBL. w0lfschild/mySIMBL: SIMBL plugin manager for macOS (https://github.com/w0lfschild/mySIMBL)

Once installed, you can just open the notification center, then click "Clear" on the bottom.

0

Just go into the activity monitor and force quit the notification center...

3
  • Welcome to Ask Different and thank you for your answer. :) Unfortunately, short answers such as this don't really provide enough detail or context to help many users. If possible, it'd be good if you could add some more info keeping in mind many users won't know how to go about doing this. Also, you may want to read How to Answer for tips on providing answers here.
    – Monomeeth
    Nov 17, 2018 at 3:05
  • Joey, this answer should be more highly rated. I hated (possibly) hundreds of notifications telling me that my external drive was not ejected properly. These notifications did not show inside Notification Center and had to manually be "Closed". Force quitting Notification Center removed them all! Thanks mate
    – Zander
    Apr 15, 2020 at 8:27
  • Zander: Agree, this turned out to be the solution that worked for me as well.
    – Eric Brown
    Nov 4, 2021 at 11:32
0

Alt-click usually works to perform one operation on multiple things.

-1

Change the annoying notification app in the notifications preferences, from "alerts" to "banners". Banners are automatically dismissed after few seconds.

-3

Run in Terminal:

killall NotificationCenter

2
  • Doesn't work on recent macOS versions.
    – HappyFace
    Jan 3 at 12:12
  • same as others solutions..
    – skywinder
    Mar 13 at 5:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .