Skip to content

Instantly share code, notes, and snippets.

@5818959
Last active August 28, 2020 07:52
Show Gist options
  • Save 5818959/76db10ea601ebd137b4f76940ab0e03c to your computer and use it in GitHub Desktop.
Save 5818959/76db10ea601ebd137b4f76940ab0e03c to your computer and use it in GitHub Desktop.
MacOS notification from terminal

MacOS notification from terminal

Create notify script:

sudo vi /usr/local/bin/notify

with content:

#!/usr/bin/osascript

on run argv
        if length of argv = 1 then
                display notification (item 1 of argv) with title "Notification" sound name "Glass"
        else if length of argv > 1 then
                display notification (item 1 of argv) with title (item 2 of argv) sound name "Glass"
        else
                return "<message> is required\nUsage: notify <message>[ <title>]"
        end if
end run

Make it executable:

sudo chmod +x /usr/local/bin/notify

Now you can trigger mac os native notification from terminal:

# notification without title
notify "Test message"

# or with custom title
notify "Test message" "Test title"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment