Clear Notifications - Big Sur - Macro (v9.1)

Clear Notifications - Big Sur - Macro (v9.1)

Clear Notifications.kmmacros (2.7 KB)

3 Likes

Can it be edited to keep clearing until none are left?

@bbodine thanks for sharing macro. It works very well.

@BernSh I don't have such an elegant solution with a Java script. But until then you may be able to do something with this solution:

2021_01_25_Support_1

08)Quit all <A3BB 210125T095541>.kmmacros (46,0 KB)

If you are using an english speaking macOS, you need to change

"NotificationCenter"
to
"Notification Center"

in the script.

Hey thanks @appleianer, I did come across your AS and am using it and it works well. Thank you! I was just seeing if this JS could do the same and maybe work a bit faster. While your solution works well, you know there is always more West to go :wink:.

It seemed the script I was using for Catalina was a bit faster than the current AS in Big Sur tho I'm not sure that it is faster and the difference is not a big deal at all. I'm glad to have and use your solution going forward :smile:.

Here is another one created by Lance Thombs on github:

1 Like

When this macro runs on multiple grouped messages, it will sometimes throw a console message that isn't desireable or expected. Adding a simple console log near the end of the file, right above the } catch (e) { resolves this issue. See snippet below to fix.

...    
        actionsToPerform.forEach(a => a.perform())
      }
      console.log(e) // <-----
    } catch (e) {
      console.log(e.message)
    }

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
			set notifications_state to "Grouped notifications - Opened"
		else
			if static text 4 of group 1 of UI element 1 of scroll area 1 of window "Notification Center" exists then
				set notifications_state to "Grouped notifications - Not opened"
			else
				set notifications_state to "Single notification"
			end if
		end if
		
		if notifications_state = "Single notification" then
			perform the last action of group 1 of UI element 1 of scroll area 1 of window "Notification Center"
		else if notifications_state = "Grouped notifications - Opened" 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 if notifications_state = "Grouped notifications - Not opened" then
			click group 1 of UI element 1 of scroll area 1 of window "Notification Center" -- Show more notifications
		end if
		
	end tell
end tell
1 Like

Thanks for your contribution @kreal ! I am trying this script in Monterey and it doesn't seem to work at the moment. I've tried changing "Notification Centre" to ""NotificationCentre"

EDIT: My bad, the script works but i was trying with Control Centre closed! Unfortunately it closes only one group at a time. My dream version of this script would clear all without even showing the panel!

Hey @splitpersonality!

Unfortunately, I don't have Monterey and not planning to upgrade soon.

I would recommend using UIbrowser to get buttons ids and update my script.

You can access UIbrowser free trial at UI Browser by PFiddlesoft
There's plenty of tutorials available on the forum and Youtube.

Good luck! :slight_smile:

Any updates for Monterey or Ventura?

Update - I created my own version that works on Monterey and Ventura, which I posted here on these forums - [Automatically Clear "Disk Not Ejected Properly" notification ( and only that one?) - #2 by majorgear](https://Dismiss Notifications)

1 Like

same here

1 Like