Skip to content

Instantly share code, notes, and snippets.

@sunnypp
Created April 8, 2019 01:44
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 sunnypp/a0b5f766038a512df345a6f02b7216b5 to your computer and use it in GitHub Desktop.
Save sunnypp/a0b5f766038a512df345a6f02b7216b5 to your computer and use it in GitHub Desktop.
Clear Notification

Sometimes when you have left the screen on, and you walked away for a short while, like:

  • Using the washroom
  • Getting a slice of cake / snacks from a friendly colleague
  • Opening the door for someone in need

Then you may miss a notification from some Apps.

While the notification showing duration should be possible to be modified, that is not too reliable.

Instead, I'll use "alert" for notifications to ensure they stays until I dismiss them.

But then I'll have to use my mouse to dismiss them --

-- Not any more

Call the script by osascript ~/cn and see the "Magic happens"

Script shamelessly copied from [https://apple.stackexchange.com/questions/300317/applescript-how-to-close-notification-alerts-from-a-specific-application]

tell application "System Events"
tell process "NotificationCenter"
set numwins to (count windows)
repeat with i from numwins to 1 by -1
click button "Close" of window i
end repeat
end tell
end tell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment