macOS 15 Sequoia で全ての通知を閉じるスクリプト

以前、以下の記事で全ての通知センターの通知パネルを閉じるAppleSciptを書きました。
neocat.hatenablog.com
これは macOS 14 でもそのまま動作していたのですが、 macOS 15 ではウィンドウの構造が変わったようでうまく動作しなくなってしまったため、書き直しました。

以前は何度かループし直さないとうまく閉じられないパネルが出てきていたのですが、今回はそういうことはない模様。
ただ、パネルが最後の1つになるとグループがなくなるようで、最後に対象を親に変えて performClose を呼び直すということをやっています。。

on performClose(theWindow)
	tell application "System Events"
		tell theWindow
			-- log (description of actions) as list
			try
				repeat with theAction in actions
					set desc to description of theAction
					if desc is "閉じる" or desc is "Close" then
						perform theAction
						exit repeat
					end if
				end repeat
			end try
		end tell
	end tell
end performClose

activate application "NotificationCenter"
tell application "System Events"
	tell process "NotificationCenter"
		if not (exists window "Notification Center") then
			return
		end if
		set theGroup to group 1 of scroll area 1 of group 1 of group 1 of window "Notification Center"
		tell theGroup
			set theWindows to every UI element as list
			set n to (count theWindows)
			repeat with i from n to 1 by -1
				tell me to performClose(item i of theWindows)
			end repeat
			tell me to performClose(theGroup)
		end tell
	end tell
end tell