Skip to content

Instantly share code, notes, and snippets.

@umkl
Created November 3, 2025 09:26
Show Gist options
  • Save umkl/905b0f03e4f4676e69270387e1c8cc9b to your computer and use it in GitHub Desktop.
Save umkl/905b0f03e4f4676e69270387e1c8cc9b to your computer and use it in GitHub Desktop.
property scriptName : "clear_notifications_applescript"
property verbose : true
on logMessage(message)
set timestamp to do shell script "date '+%Y-%m-%d %H:%M:%S'"
set fullMessage to timestamp & " [" & scriptName & "] " & message
if verbose then
log fullMessage
else
display dialog fullMessage
end if
end logMessage
on openNotificationCenter()
tell application "System Events"
key code 160 -- F8 (Notification Center)
delay 0.5
end tell
end openNotificationCenter
on getNotificationCenterProcess()
tell application "System Events"
if exists process "NotificationCenter" then
return process "NotificationCenter"
end if
end tell
return missing value
end getNotificationCenterProcess
on pressClearAll()
set nc to getNotificationCenterProcess()
if nc is missing value then return false
tell application "System Events"
tell nc
try
set clearButtons to (buttons whose name contains "Clear")
repeat with b in clearButtons
perform action "AXPress" of b
delay 0.2
end repeat
return true
on error errMsg
logMessage("Error pressing Clear: " & errMsg)
return false
end try
end tell
end tell
end pressClearAll
on closeNotifications()
openNotificationCenter()
delay 0.3
if pressClearAll() then
logMessage("Cleared notifications")
else
logMessage("No Clear button found")
end if
end closeNotifications
closeNotifications()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment