Automatically Clear "Disk Not Ejected Properly" notification ( and only that one?)

I got it working on Ventura 13.0.1 by taking another script for closing all notifications and modifying it to only act on this specific notification.

tell application "System Events"
	try
		set _groups to groups of UI element 1 of scroll area 1 of group 1 of window "Notification Center" of application process "NotificationCenter"
		
		repeat with _group in _groups
			set temp to value of static text 1 of _group
			if temp contains "Disk Not Ejected Properly" then
				perform (first action of _group where description is "Close")
			end if
		
		end repeat
		
	end try
end tell

I also made a Monterey version for my macbook that hasn't been upgraded yet.

tell application "System Events"
	tell process "Notification Center"
		set numwins to (count windows)
		repeat with i from numwins to 1 by -1
			tell window i
				set temp to value of static text 1 of group 1 of UI element 1 of scroll area 1
			end tell
			if temp contains "Disk Not Ejected Properly" then
				perform (first action of group 1 of UI element 1 of scroll area 1 of window i where description is "Close")
			end if
		end repeat
	end tell
end tell

Enjoy!

7 Likes