30

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

15 Answers 15

20
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
    Commented Sep 28, 2019 at 15:30
  • How do you invoke this? Commented Jan 16, 2020 at 20:28
  • 4
    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
    Commented 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 Commented Aug 19, 2021 at 22:47
8

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
    Commented Jun 6, 2016 at 9:28
  • Brilliant thank you! You can copy paste the script into Alfred as well. Commented 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? Commented Dec 16, 2018 at 22:26
  • yes, that's the idea. I use it periodically to clear out a lot of notifications.
    – Kem Mason
    Commented Dec 18, 2018 at 20:24
  • If u wanna stay away from scripts this is the answer! Commented 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. Commented Mar 30, 2020 at 12:39
6

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
    Commented 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
    Commented Oct 5, 2021 at 14:31
  • No, that won't even hide the notification for a second (which the previous version did).
    – HappyFace
    Commented 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
    Commented Feb 9, 2022 at 15:41
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
    Commented May 4, 2015 at 18:18
  • @sea Haven't got comments yet
    – Sébastien
    Commented May 4, 2015 at 18:50
  • 1
    I don't see any "small x" on El Capitan 10.11.1
    – Meekohi
    Commented Nov 3, 2015 at 14:35
  • 2
    You can close by day, if you hover over the day header line.
    – Tetsujin
    Commented 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
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.

1

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

4
  • 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
    Commented 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
    Commented Apr 15, 2020 at 8:27
  • Zander: Agree, this turned out to be the solution that worked for me as well.
    – Eric Brown
    Commented Nov 4, 2021 at 11:32
  • I can see why people didn’t like that it doesn’t cover the “1 click” requirement of the question, but in a pinch it’s the easiest way to get rid of all notifications (as of Monterey). Killing the process (it will restart on its own) clears all notifications. Commented May 12 at 10:53
0

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

1
  • This did not work for me on Big Sur. Commented Dec 14, 2022 at 11:51
0

This answer suggests that on Big Sur in its current release there is no satisfactory way to dismiss notifications with a single click (or keyboard shortcut). Instead, this answer explains alternative ways to dismiss them that are not noted elsewhere in this thread.

Two-finger swipe right on the notification group works on Big Sur with the Macbook's trackpad (not sure about Yosemite). It also works with left-click and drag to the right. I assume this would work with an Apple Magic Mouse or Magic Trackpad as well.

This doesn't "clear" all notifications permanently. They will still show if you open the notification sidebar. They will also show if another message comes through; instead of seeing 1 notification it will show N + 1 notifications available.

This thread is similar to Dismiss MacOS Big Sur notifications with keyboard.

1
  • The two-finger swipe right works on Monterrey as well, but has the same behavior of not closing the notifications; the next notification to come through will show all previously unclosed notifications. Commented Jan 18, 2023 at 2:25
0

You can use:

launchctl unload -w /System/Library/LaunchAgents/com.apple.notificationcenterui.plist

Note that its only shuts the service down and not clearing the notification.

To bring it back use:

launchctl load -w /System/Library/LaunchAgents/com.apple.notificationcenterui.plist

0

Here's what worked for me on Big Sur.

1. Create a clear_notifications script

You can do that by running this script from your terminal

write_target=~/bin/clear_notifications
mkdir ~/bin
cat << EOF > $write_target
#!/usr/bin/osascript

# Usage: clear_notifications [partial_title]
#
# Clears notifications from the notification center if they contain the string in [partial_title].
# If no arg is passed in, all notifications are cleared.

on run argv
  tell application "System Events"
     try
       set _groups to groups of UI element 1 of scroll area 1 of group 1 of window "Notification Center" of application process "NotificationCenter"
      repeat with _group in _groups
        set temp to value of static text 1 of _group
          set _actions to actions of _group # Get all the actions within this group
          set isInScope to true

          if (count of argv) > 0 then
            set searchTerm to item 1 of argv
            if temp does not contain searchTerm then
              log "Didn't find any notifications matching " & searchTerm
              set isInScope to false
            end if
          end if

          if isInScope then
            if exists (first action of _group where description is "Clear All") then
              log "Found 'clear all' for " & temp
              perform (first action of _group where description is "Clear All")
            else if exists (first action of _group where description is "Close") then
              log "Found close for " & temp
              perform (first action of _group where description is "Close")
            else
              log "Didn't find close action for " & temp
            end if
          end if

      end repeat
    on error errMsg
        log "Error: " & errMsg
    end try
  end tell
end run
EOF
chmod u+x $write_target

2. Connect the script to a keyboard shortcut.

You can do this using the keyboard shortcut instructions from the accepted answer (similar instructions here), but I find automator clunky and cumbersome for such a simple task. I much prefer using Better Touch Tool.

  • Go to Better Touch Tool configuration
  • In the left panel, select "All Apps"
  • Add a new keyboard shortcut of your choice and choose Execute Terminal Command (Async, non-blocking) as the trigger.
  • Enter ~/bin/clear_notifications into the textbox where it says Enter Terminal Command

better touch tool add shortcut

3. (Optional) Create shortcuts to clear specific notifications

If you just want to clear, say, Calendar notifications, where the title of the notification has the word "Calendar" in it, you can enter the following in the terminal command text box instead. I have terminal notifications from iTerm that let me know when builds are complete, and I mostly use it for that.

  • Enter ~/bin/clear_notifications "Calendar" into the textbox where it says Enter Terminal Command
-1

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

-1

Run in Terminal:

killall NotificationCenter

3
  • 1
    Doesn't work on recent macOS versions.
    – HappyFace
    Commented Jan 3, 2022 at 12:12
  • same as others solutions..
    – skywinder
    Commented Mar 13, 2022 at 5:57
  • this still works on MacOS Sonoma 14.5
    – Zion
    Commented Jul 5 at 19:00

You must log in to answer this question.

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