Close Notifications ⌘;

Missing notifications

I was missing all these Slack messages.

So i turned on persistent notifications, ‘Alerts’ in Apple vernacular.

alerts-settings

Too many notifications

But now every time I got a message I’d need to hover over the notification and manually close it.

Or id just leave it and it’d hover in my periphery.

Just right

So i finally added a keyboard shortcut to close notifications with Keyboard Maestro and it’s amazing.

This requires Keyboard Maestro

keyboard-maestro

Apple Script snippet ⌘;

tell application "System Events"
	try
		repeat
			set _groups to groups of UI element 1 of scroll area 1 of group 1 of window "Notification Center" of application process "NotificationCenter"
			set numGroups to number of _groups
			if numGroups = 0 then
				exit repeat
			end if
			repeat with _group in _groups
				set _actions to actions of _group
				set actionPerformed to false
				repeat with _action in _actions
					if description of _action is in {"Clear All", "Close"} then
						perform _action
						set actionPerformed to true
						exit repeat
					end if
				end repeat
				if actionPerformed then
					exit repeat
				end if
			end repeat
		end repeat
	end try
end tell

Adapted from: AppleScript to close all notifications on macOS Big Sur, Monterey, and Ventura

Bonus!

Script to expand grouped notifications:

grouped-notifications

Expand Notifications ⌘'

tell application "System Events"
	try
		-- Get the Notification Center window
		repeat
			set _groups to groups of UI element 1 of scroll area 1 of group 1 of window "Notification Center" of application process "NotificationCenter"
			set numGroups to number of _groups
			
			if numGroups = 0 then
				exit repeat
			end if
			
			repeat with _group in _groups
				-- Look for any "Show More" or "Expand" buttons/actions
				set _buttons to buttons of _group
				repeat with _button in _buttons
					if name of _button is in {"Show More", "Show", "Expand"} then
						click _button
						delay 0.5 -- Add a small delay to allow for animation
					end if
				end repeat
				
				-- Check for expandable actions
				set _actions to actions of _group
				repeat with _action in _actions
					if description of _action is in {"Show More", "Show", "Expand"} then
						perform _action
						delay 0.5 -- Add a small delay to allow for animation
					end if
				end repeat
			end repeat
		end repeat
	end try
end tell

Want to hear from me?

I send infrequent, acyclic updates. Sign up for them here:

← All posts