Skip to content

Instantly share code, notes, and snippets.

@sbritorodr
Created July 8, 2023 18:36
Show Gist options
  • Select an option

  • Save sbritorodr/a84840ae7607ff89ba46d8e9810a467e to your computer and use it in GitHub Desktop.

Select an option

Save sbritorodr/a84840ae7607ff89ba46d8e9810a467e to your computer and use it in GitHub Desktop.
MacOS command script for creating notifications
# Simple script for making a system notification whenever a command process has ended.
# Working on MacOS Ventura 13.1 but should work with something with Apple Script support
# Example use: cowsay "Hello, World" && notifyme -m "Cowsay said something" -t "Cowsay" -s "Submarine"
# It is recommended to paste this inside a ~/.zshrc_personal file and link it inside ~/.zshrc with "source ~/.zshrc_personal"
# Made by sbritorodr
notifyme () {
DEFAULT_BODY="A terminal process has ended"
DEFAULT_TITLE="Process Completed!"
DEFAULT_SOUND="Hero"
print_help() {
echo "notifyme - Send a notification message"
echo "Usage: notifyme [OPTIONS]"
echo "Options:"
echo " -h Prints this message"
echo " -m BODY The body of the notification message"
echo " -t TITLE The title of the notification"
echo " -s SOUND The sound to play for the notification."
echo " Sounds are stored in ~/Library/Sounds or"
echo " in /System/Library/Sounds"
}
while getopts "m:t:s:" opt
do
case $opt in
(m) BODY="$OPTARG" ;;
(t) TITLE="$OPTARG" ;;
(s) SOUND="$OPTARG" ;;
(h) print_help; exit 0 ;;
(\?) exit 1 ;;
esac
done
BODY=${BODY:-$DEFAULT_BODY}
TITLE=${TITLE:-$DEFAULT_TITLE}
SOUND=${SOUND:-$DEFAULT_SOUND}
osascript -e "display notification \"$BODY\" with title \"$TITLE\" sound name \"$SOUND\""
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment