UI Scripting - macOS Big Sur Notification Center

Hi KM User, I had an Applescript under macOS Catalina with which I could close notifications via the Notification Center:

my closeNotification()

on closeNotification()
   tell application "System Events" to tell process "Notification Center"
      click button 1 of first item of windows
   end tell
end closeNotification

Unfortunately Apple changed the design under macOS Big Sur and did not integrate the buttons in this form anymore:

Sceenshot

With the help of the YouTube tutorial of @DanThomas I created the following with the UI Browser App:

activate application "NotificationCenter"
tell application "System Events"
   tell process "Mitteilungszentrale"
      click button 1 of group 1 of UI element 1 of scroll area 1 of window 1
   end tell
end tell

"Mitteilungszentrale" is written there, because I use a german macOS.

Unfortunately I always get an error message:

Can anyone help me there or would they have a different solution for macOS Big Sur?

Using your pointer to UI Browser and your code as a base I have something that works. It is a bit clunky as it depends on the notification having a "Close" action. All of the notifications I care about have this action so it works for me.

activate application "NotificationCenter"
tell application "System Events"
	tell process "Notification Center"
		click group 1 of UI element 1 of scroll area 1 of window "Notification Center"
		set theActions to actions of group 1 of UI element 1 of scroll area 1 of window "Notification Center"
		repeat with theAction in theActions
			if description of theAction is "Close" then
				tell group 1 of UI element 1 of scroll area 1 of window "Notification Center"
					perform theAction
				end tell
			end if
		end repeat
	end tell
end tell
2 Likes

I was able to solve the problem for myself @ajanian
I found out that the cursor needs to be over the notification for the Uli script to work properly. Take a look at the video here:

Clear Notifications in Big Sur

Thanks. I would prefer to not move the mouse so I think I'll stick with mine. I was going for full keyboard.

I don't move the mouse either. I do everything with a single shortcut using the keyboard :wink:

and you move the mouse back to the original location or the mouse ends being over the Notification Center?

@ajanian the mouse/cursor position is saved and reset after script execution

It happens so fast that you hardly notice it.

I have tried your UI script and it does not work properly for me.

hi, looks this code not working in macos ventura, is there any way to make it work in venture?