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

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

Clear Notifications.kmmacros (2.7 KB)

2 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:

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