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