Clear Notifications in Big Sur

This macro is similar to others for clearing out notifications in Big Sur. Right now, it only supports a single group. I haven't had multiple groups of notifications to test yet.

If anyone has figured out a cleaner way to do this, I would love to hear it. I couldn't find a clean way to move the mouse or get access to the hidden "X" and "Clear All" buttons without having the mouse hover over the notification in Big Sur.

Clear Notification Center.kmmacros (3.3 KB)

@rjames86I don't know if this is wanted by Apple or if it is a bug.
Unfortunately I couldn't do it without a mouse move, but it works very well.

Here is a short video:

@Notification Forum Macros <FF57 201203T194050>.kmmacros (504,5 KB)

Copied Image

The cursor/mouse coordinates refer to a 15 inch MBP.

Yep, I ran into the same thing. I'm fairly certain it was an intentional design choice by Apple.

One thing you can do in your macro is return the mouse to its original location. See the last action in my screenshot for how to do that.

@rjames86 the idea I had also, when I saw your screenshot :wink:

Really like M1 Macs, really not liking the mess that is the new notifications.

So if I highlight a notification so that the X appears and run this applescript

my closeNotifications()

on closeNotifications()
   tell application "System Events" to tell process "NotificationCenter"
      click button 2 of group 1 of UI element of scroll area 1 of window 1
   end tell
end closeNotifications

It should close, right? But does not close at all for me.

I keep everything unstacked because it's easier to manage that way. Hoping to find way to just nuke all notifications after I've looked through them. I keep them on screen permanently as there are important things I will not notice otherwise, and do this on my main iMac and M1 Macbook Air, so I have them in two places. Really want to my "clear all notifications" solved.

Watch the first couple of minutes of @appleianer's vid above.

The script does NOT work until he places the cursor above the notification.

I don't have Big Sur to test, so I can't see if there's a way around that.

If I did I'd be digging around the window to see if it has any actions available or UI elements that do have actions available.

tell application "System Events" to tell process "NotificationCenter"
   tell window 1
      
      set diagnosticsList to {¬
         "----- PROPERTIES -----", ¬
         properties, ¬
         "----- UI ELEMENTS -----", ¬
         UI elements, ¬
         "----- ATTRIBUTES -----", ¬
         attributes, ¬
         "----- ACTIONS -----", ¬
         actions, ¬
         "----- END -----"}
      
   end tell
end tell

-Chris

Dito @ppayne

I have found this solution for it:

2020_12_17_Support_1

It is slower than macOS Catalina... but it is better than nothing.
If you use an english macOS, then you have to change "NotificationCenter" to "Notification Center" in the script.

08)Quit all <A3BB 201217T082937>.kmmacros (46,0 KB)

1 Like

Hey @appleianer,

I usually like to visualize this sort of thing in its own result window using the ‘Source’ view with Pretty-Print ON:

This way I can eyeball everything, and I can search for text.

I have keyboard shortcut that let me quickly toggle between Best, Source, and AEPrint views.

Congrats on working through the problem.

-Chris


P.S. The AppleScript IDE above is Script Debugger 7.0.12 running on macOS 10.12.6.

I may have discovered a way to clear the notifications without the need to move the mouse to show the Clear All button. My tests so far of this script have been successful without the need to move the mouse.

var app = Application("System Events");

var notificationCenter = app.processes.byName("Notification Center");

var group = notificationCenter.windows
  .at(0)
  .scrollAreas.at(0)
  .uiElements.at(0)
  .groups.at(0);

var actions = group.actions.whose({
  _or: [{ description: "Clear All" }, { description: "Close" }],
});

try {
  var uniqueNames = new Set();
  var actionsToPerform = [];
  actions().forEach((a) => {
    if (!uniqueNames.has(a.name())) {
      actionsToPerform.push(a);
    }
    uniqueNames.add(a.name());
  });

  var uniqueDescriptions = new Set(
    actionsToPerform.map((a) => a.description())
  );
  if (uniqueDescriptions.has("Clear All")) {
    var clearAll = actionsToPerform.filter(
      (a) => a.description() === "Clear All"
    )[0];
    clearAll.perform();
  } else {
    actionsToPerform.forEach((a) => a.perform());
  }
} catch (e) {
  console.log(e.message);
  throw e;
}
3 Likes

Outstanding! I will download and test this right away!

This worked great for me using "Execute JavaScript For Automation" as the action. I removed the last line throw e; so if the action was fired without any notifications present the code completes instead of erroring.

Created a new macro here. Clear Notifications - Big Sur - Macro (v9.1)

Thanks!

1 Like

The following script allows, without moving the mouse, to:

  1. Close single notification.
  2. Show more notifications.
  3. Clear all notifications.
tell application "System Events"
	tell process "Notification Centre"
		
		if button "Confirm Show Less" of UI element 1 of scroll area 1 of window "Notification Center" exists then
			click button "Clear" of UI element 1 of scroll area 1 of window "Notification Center"
			delay 0.25
			click button "Clear" of UI element 1 of scroll area 1 of window "Notification Center"
			
		else
			
			set static_text_nr to 3
			set static_text_list to {}
			set count_static_text to count static text of group 1 of UI element 1 of scroll area 1 of window "Notification Center"
			set count_static_text to count_static_text - 2
			
			repeat with x from 1 to count_static_text
				
				set value_of to get value of static text static_text_nr of group 1 of UI element 1 of scroll area 1 of window "Notification Center"
				set end of static_text_list to value_of
				
				if static_text_nr = (count static text of group 1 of UI element 1 of scroll area 1 of window "Notification Center") then exit repeat
				
				set static_text_nr to static_text_nr + 1
			end repeat
			
			log static_text_list
			set list_item to 1
			
			
			if last item of static_text_list contains "more notification" then
				click group 1 of UI element 1 of scroll area 1 of window "Notification Center" -- Show more notifications
			else
				perform the last action of group 1 of UI element 1 of scroll area 1 of window "Notification Center"
			end if
			
		end if
		
	end tell
end tell

--if testvar contains "more notification" then return "YES"
5 Likes