Skip to content

Instantly share code, notes, and snippets.

@dfed
Last active January 17, 2019 19:37
Show Gist options
  • Save dfed/a8882b849905a377742624b43026f086 to your computer and use it in GitHub Desktop.
Save dfed/a8882b849905a377742624b43026f086 to your computer and use it in GitHub Desktop.
Post macOS notification when your terminal command is done
brew install terminal-notifier
function notify {
local title="Succeeded"
# Capture the parameter list for later display.
local message=$@
if [ $# -ne 0 ]; then
# Execute the parameters.
eval $@
else
# Get the last line of history.
message="$(history 1 | awk '{$1="";$2="";print}')"
fi
# Get the exit status of the last-run command.
local retVal=$?
if [ $retVal -ne 0 ]; then
title="Failed"
fi
# Notify the user that the command is done.
terminal-notifier -title "$title" -message "$message" -sound "default" -ignoreDnD
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment