Today, I am going to show you a tip to send desktop notification from command line in MacOS, which is useful for Mac automation.
To send the desktop notification, we will use the osascript
utility.
First, open the terminal then try to execute the following command:
$ osascript -e 'display notification "This message should be showing on the notification"'
You should see this notification showing on your Mac immediately.
Well, we can set a custom notification title, try this command out:
$ osascript -e 'display notification "This message should be showing on the notification" with title "Coding Tips"'
You can even set subtitle for the notification:
$ osascript -e 'display notification "This message should be showing on the notification" with title "Coding Tips" subtitle "blog.petehouston.com"'
or, even better with some sound effects, like this:
$ osascript -e 'display notification "This message should be showing on the notification" with title "Coding Tips" subtitle "blog.petehouston.com" sound name "Pop"'
Sound effects can be found under /System/Library/Sounds
directory.
$ ls -asl /System/Library/Sounds
total 7536
-rw-r--r-- 1 root wheel 216K May 9 16:30 Basso.aiff
-rw-r--r-- 1 root wheel 394K May 9 16:30 Blow.aiff
-rw-r--r-- 1 root wheel 218K May 9 16:30 Bottle.aiff
-rw-r--r-- 1 root wheel 202K May 9 16:30 Frog.aiff
-rw-r--r-- 1 root wheel 609K May 9 16:30 Funk.aiff
-rw-r--r-- 1 root wheel 464K May 9 16:30 Glass.aiff
-rw-r--r-- 1 root wheel 297K May 9 16:30 Hero.aiff
-rw-r--r-- 1 root wheel 198K May 9 16:30 Morse.aiff
-rw-r--r-- 1 root wheel 422K May 9 16:30 Ping.aiff
-rw-r--r-- 1 root wheel 458K May 9 16:30 Pop.aiff
-rw-r--r-- 1 root wheel 213K May 9 16:30 Purr.aiff
-rw-r--r-- 1 root wheel 433K May 9 16:30 Sosumi.aiff
-rw-r--r-- 1 root wheel 420K May 9 16:30 Submarine.aiff
-rw-r--r-- 1 root wheel 159K May 9 16:30 Tink.aiff
If you want to add more sound effects, put the file into this directory or ~/Library/Sounds
.
Congratulation! Now you know how to send desktop notification from command line in MacOS.
Have fun!