Last active
October 1, 2026 20:05
-
-
Save erikrose/5d278821ae368961d7238aca3e63379f to your computer and use it in GitHub Desktop.
Dismiss macOS notifications
This file contains hidden or 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
| // Modified from | |
| // https://gist.github.com/lancethomps/a5ac103f334b171f70ce2ff983220b4f | |
| "use strict"; | |
| function run() { | |
| const CurrentApplication = (() => { | |
| const app = Application.currentApplication(); | |
| app.includeStandardAdditions = true; | |
| return app; | |
| })(); | |
| const SystemEvents = Application("System Events"); | |
| const NotificationCenter = | |
| SystemEvents.processes.byName("NotificationCenter"); | |
| const macOSSequoiaOrGreater = | |
| parseFloat(CurrentApplication.systemInfo().systemVersion) >= 15.0; | |
| const notificationGroups = () => { | |
| const windows = NotificationCenter.windows; | |
| if (windows.length === 0) { | |
| return []; | |
| } | |
| return macOSSequoiaOrGreater | |
| ? windows // "Clear all" heirarchy | |
| .at(0) | |
| .groups.at(0) | |
| .groups.at(0) | |
| .scrollAreas.at(0) | |
| .groups() | |
| .at(0) | |
| .uiElements() | |
| .concat( | |
| windows // "Close" hierarchy | |
| .at(0) | |
| .groups.at(0) | |
| .groups.at(0) | |
| .scrollAreas.at(0) | |
| .groups() | |
| ) | |
| : windows.at(0).groups.at(0).scrollAreas.at(0).uiElements.at(0).groups(); | |
| }; | |
| const findCloseAction = group => { | |
| const [closeAllAction, closeAction] = group.actions().reduce( | |
| (matches, action) => { | |
| switch (action.description()) { | |
| case "Clear All": | |
| return [action, matches[1]]; | |
| case "Close": | |
| return [matches[0], action]; | |
| default: | |
| return matches; | |
| } | |
| }, | |
| [null, null] | |
| ); | |
| return closeAllAction ?? closeAction; | |
| }; | |
| const actions = notificationGroups().map(findCloseAction); | |
| for (const action of actions) { | |
| action?.perform(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment