Created
March 13, 2020 13:57
-
-
Save andredsp/6b39bd7fbfe3e9f51a4232646ebe18cc to your computer and use it in GitHub Desktop.
Close All Notifications (macOS)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
to closeIncorrectEjections() | |
set totalClosed to 0 | |
tell application "System Events" | |
tell process "NotificationCenter" | |
set closedWindows to 1 -- force first repeat loop | |
repeat until closedWindows = 0 | |
set closedWindows to 0 | |
set numwins to (count windows) | |
log "opened windows: " & numwins | |
repeat with windowIndex from numwins to 1 by -1 | |
tell window windowIndex | |
set titleText to value of static text 1 | |
end tell | |
if titleText contains "Disk Not Ejected Properly" then | |
click button "Close" of window windowIndex | |
set closedWindows to closedWindows + 1 | |
end if | |
end repeat | |
set totalClosed to totalClosed + closedWindows | |
log "closed " & closedWindows & " windows" | |
delay 0.25 -- be sure the last dialog was closed | |
end repeat | |
end tell | |
end tell | |
return totalClosed | |
end closeIncorrectEjections | |
-- this is the main entrance method. | |
on run | |
try | |
set totalClosed to closeIncorrectEjections() | |
display notification "" & totalClosed & " notifications were closed." with title "Close Notifications" subtitle "Success" | |
on error | |
display notification "There was an error. Try again." with title "Close Notifications" subtitle "Fail" | |
end try | |
end run |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment