Choose Apple menu > System Preferences, then click Notifications. Select an app in the left column. To change the notification style, select Banners or Alerts. Or select None.
Open TerminalClick the Launchpad icon in the Dock, type Terminal in the search field, then click Terminal. In the Finder , open the /Applications/Utilities folder, then double-click Terminal.
Use osascript
. For example:
osascript -e 'tell app "Finder" to display dialog "Hello World"'
Replacing “Finder” with whatever app you desire. Note if that app is backgrounded, the dialog will appear in the background too. To always show in the foreground, use “System Events” as the app:
osascript -e 'tell app "System Events" to display dialog "Hello World"'
Read more on Mac OS X Hints.
Use this command to trigger the notification center notification from the terminal.
osascript -e 'display notification "Lorem ipsum dolor sit amet" with title "Title"'
If you're using any Mac OS X version which has Notification Center, you can use the terminal-notifier gem. First install it (you may need sudo
):
gem install terminal-notifier
and then simply:
terminal-notifier -message "Hello, this is my message" -title "Message Title"
See also this OS X Daily post.
With AppleScript:
display notification "Notification text" with title "Notification Title" subtitle "Notification sub-title" sound name "Submarine"
With terminal/bash and osascript
:
osascript -e 'display notification "Notification text" with title "Notification Title" subtitle "Notification sub-title" sound name "Submarine"'
Does not take the sub-heading nor the sound tough.
With AppleScript:
display alert "Alert title" message "Your message text line here."
With terminal/bash and osascript
:
osascript -e 'display alert "Alert title" message "Your message text line here."'
Add a line in bash for playing the sound after the alert line:
afplay /System/Library/Sounds/Hero.aiff
Add same line in AppleScript, letting shell script do the work:
do shell script ("afplay /System/Library/Sounds/Hero.aiff")
List of macOS built in sounds to choose from here.
Paraphrased from a handy article on terminal and applescript notifications.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With