Skip to content

Instantly share code, notes, and snippets.

@Strajk
Created November 29, 2024 07:00
Show Gist options
  • Select an option

  • Save Strajk/4eccea362807627d7c0bae27e9d20ae2 to your computer and use it in GitHub Desktop.

Select an option

Save Strajk/4eccea362807627d7c0bae27e9d20ae2 to your computer and use it in GitHub Desktop.
// Name: Clear MacOS notifications
// Description: Only visible notifications – clearing not visible notifications is not possible
import "@johnlindquist/kit"
await jxa(`
Application("System Events")
.applicationProcesses.byName("NotificationCenter")
.windows[0]
.groups[0]
.scrollAreas[0]
.uiElements[0]
.groups()
.map(banner => banner.actions().slice(-1)[0])
.forEach(banner => banner.perform())
`)
// Inspired by Kit's "applescript" function
async function jxa(script: string) {
await writeFile(kenvTmpPath("clear-macos-notifications.jxa"), script);
await execa("osascript", ["-l", "JavaScript", kenvTmpPath("clear-macos-notifications.jxa")]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment