Skip to content

Instantly share code, notes, and snippets.

@Down10
Created January 3, 2017 05:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Down10/8313be11b45da69e8ae7826daec575f9 to your computer and use it in GitHub Desktop.
Save Down10/8313be11b45da69e8ae7826daec575f9 to your computer and use it in GitHub Desktop.
Close all of the annoying mac OS notification windows at once! Just make a new service routine in Automator, pick "Run Applescript" with `no input` in `any application`, paste in this script, and save as a Service. Then apply a keystroke and enjoy!
on run {}
if isNotificationCenterRunning() then
my closeAllNotes()
end if
end run
on closeAllNotes()
tell application "System Events"
tell application process "NotificationCenter"
set everyNote to every window
set noteCount to (count everyNote)
if noteCount > 0 then
repeat with thisNote in everyNote
try
tell thisNote
click button 1 -- "Close" in most cases
end tell
on error
if noteCount > 0 then
my closeAllNotes() -- Try it again
else
exit repeat
end if
end try
end repeat
end if
end tell
end tell
end closeAllNotes
on isNotificationCenterRunning()
set isRunning to false
tell application "System Events"
set isRunning to (name of every application process) contains "NotificationCenter"
end tell
isRunning
end isNotificationCenterRunning
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment