Skip to content

Instantly share code, notes, and snippets.

@brianarn
Last active May 24, 2018 21:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brianarn/62b47c155bb72699aa7daa592ada7c14 to your computer and use it in GitHub Desktop.
Save brianarn/62b47c155bb72699aa7daa592ada7c14 to your computer and use it in GitHub Desktop.
Using `osascript` to issue notifications in MacOS

Thanks to a wonderful tip from @brianloveswords I've started using osascript alongside say to help me notice when long-running jobs are done.

You can also put a sound with the notification, which is cool, and I wanted a quick way to test every sound on the system, so I ran this:

for f in /System/Library/Sounds/*.aiff
do
file=$(basename -s .aiff $f)
osascript -e "display notification \"$file\" with title \"$file\" sound name \"$file\""
sleep 1
done

It cycles through each sound, creating a notification, with a title, so you can get a taste of all the options available to you.

I also just created this small bash function that I'm now using in some scripts around this, to do both a say and an alert at me.

announce() {
  osascript -e "display notification \"$1\" with title \"APP NAME HERE\" sound name \"Glass\""
  say $1
}

Now I can announce "Thing complete" in the script and it works.

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