-
-
Save lucaswilric/b7c68bb5ae502990cccf3842c2a2c2bd to your computer and use it in GitHub Desktop.
Bash wrapper script to create an OSX notification when my command completes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
## Create an OSX notification when my command completes. | |
# | |
# Usage: notify-done.sh <command> | |
# | |
# For convenience, use a Bash alias: | |
# | |
# alias n="notify-done.sh " | |
# | |
# (The trailing space tells the shell to expand any following aliases, so you | |
# can use your existing aliases with `n`). | |
# First, capture the input and give it a descriptive name. | |
# | |
cmd="$@" | |
# Then, execute it, passing in the current environment. | |
# | |
env bash -c "$cmd" | |
# Capture the result so that we can exit transparently (i.e. so that this script | |
# doesn't "swallow" exit codes that might be important) when the time comes. | |
# | |
exit_code=$? | |
# Compose a notification message. | |
# | |
msg="$exit_code: $1 has completed." | |
# Decide on a notification title. | |
# | |
if [[ "$exit_code" == "0" ]] | |
then | |
result=Success | |
else | |
result=Failure | |
fi | |
# Display the notification, using the message and title we put together above. | |
# | |
# You can see the list of available sounds by opening System Preferences > | |
# Sounds > Sound Effects. | |
# | |
osascript -e "display notification \"$msg\" with title \"$result\" sound name \"Glass\"" | |
# Exit transparently, because using this notification wrapper shouldn't change | |
# how the wrapped command be haves -- that would be rude. | |
# | |
exit $exit_code |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For anybody on Linux, you might have
notify-send
, in which case replace the 'osascript' line with this: