Skip to content

Instantly share code, notes, and snippets.

@jvenezia
Created January 13, 2025 09:49
Close All Notifications on macOS with a Keyboard Shortcut

Close All Notifications on macOS with a Keyboard Shortcut

This tutorial explains how to create a custom keyboard shortcut to close all macOS notifications using Automator and System Settings.


Step 1: Open Automator

  1. Open Automator (use Spotlight Search or find it in Applications).
  2. In the window that appears, select Quick Action as the document type.

Step 2: Configure the Quick Action

  1. At the top of the Automator window:

    • Set Workflow receives to no input.
    • Set in to any application.
  2. In the left sidebar, search for Run AppleScript.

  3. Drag the Run AppleScript action into the workflow pane on the right.


Step 3: Add the Script

Paste the following AppleScript into the Run AppleScript block in Automator:

tell application "System Events"
    tell process "NotificationCenter"
        if not (window "Notification Center" exists) then return
        set alertGroups to groups of first UI element of first scroll area of first group of window "Notification Center"
        repeat with aGroup in alertGroups
            try
                perform (first action of aGroup whose name contains "Close" or name contains "Clear")
            on error errMsg
                log errMsg
            end try
        end repeat
        return ""
    end tell
end tell

Test the script by clicking Run in Automator. If notifications are cleared, proceed to the next step.


Step 4: Save the Quick Action

  1. Go to File > Save in Automator.
  2. Name your Quick Action (e.g., CloseNotifications) and click Save.

Step 5: Assign a Keyboard Shortcut

  1. Open System Settings (or System Preferences).
  2. Navigate to Keyboard > Keyboard Shortcuts.
  3. Select App Shortcuts from the list on the left.
  4. Click the + button to add a new shortcut:
    • Application: Choose All Applications.
    • Menu Title: Enter the exact name of your Quick Action (e.g., CloseNotifications).
    • Keyboard Shortcut: Assign a shortcut (e.g., Command + Option + N).
  5. Click Add.

Step 6: Use Your Shortcut

Press the assigned keyboard shortcut to run the Quick Action and clear all notifications. The script will execute, clearing all visible notifications from the macOS Notification Center.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment