How to Display macOS Notifications from the Command Line

John John (304)
5 minutes

In this guide, we're going to use AppleScript and a tool called osascript to display macOS notifications. AppleScript is a scripting language created by Apple that allows us to automate control of Mac applications, and osascript is a tool that allows us to execute AppleScript from the command line.

With these tools, we can easily display macOS notifications from the command line or from within shell scripts.

Posted in these interests:
h/mac128 guides
h/apple162 guides

Text-only notification

The display command can be run like this:

display notification "test notification!"

But if we want to execute this from the command line, we need to use osascript with the -e flag.

osascript -e 'display notification "test notification!"'

Notification with a title

osascript -e 'display notification "test notification!" with title "This is the title"'

Run any of these examples from the Terminal application (or your favorite terminal emulator), and you'll see the notifications appear!

Add a new account to the mail app on your Mac.
2 minutes

If you are new to Mac, or simply don't consider yourself tech-savvy, you may be struggling to do some of the everyday tasks necessary to use your Mac.