Created
November 28, 2017 19:21
-
-
Save GeneralD/94c1ab70534bdd8b435e18ad02d5a515 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 sh | |
## This script uses several commands. They can be install with... | |
## $ gem install notify-my-android | |
## $ gem install prowl | |
## $ brew install terminal-notifier | |
NMA_KEY=${NMA_KEY:-"YOUR_KEY"} | |
PROWL_KEY=${PROWL_KEY:-"YOUR_KEY"} | |
# print usage and exit | |
usage_exit() { | |
cat << EOB 1>&2 | |
Usage: ${0##*/} [-aim] [-t title] [-b message body] [-p priority (optional)] | |
-t title (required) | |
-b message body (required) | |
Platforms: | |
You should select at leaset one. | |
-a notify to Android | |
-i notify to iOS | |
-m notify to this Mac | |
Priority: | |
-p priority [-2|-1|0|1|2] (optional) | |
EOB | |
exit 1 | |
} | |
# parse args | |
while getopts aimt:b:p:h OPT; do | |
case $OPT in | |
a) NOTIFY_ANDROID=1;; | |
i) NOTIFY_IOS=1;; | |
m) NOTIFY_MAC=1;; | |
t) NOTIFY_TITLE=$OPTARG;; | |
b) NOTIFY_BODY=$OPTARG;; | |
p) NOTIFY_PRIORITY=$OPTARG;; | |
h) usage_exit;; | |
\?) usage_exit;; | |
esac | |
done | |
shift $((OPTIND - 1)) | |
# check user sets platform | |
if [ -z $NOTIFY_ANDROID ] && [ -z $NOTIFY_IOS ] && [ -z $NOTIFY_MAC ]; then | |
cat << EOB 1>&2 | |
Warn: Set one or more notification platform(s)! | |
EOB | |
usage_exit | |
fi | |
# check user sets title or message | |
if [ -z $NOTIFY_TITLE ] && [ -z $NOTIFY_BODY ]; then | |
cat << EOB 1>&2 | |
Warn: Set at least either title or message! | |
EOB | |
usage_exit | |
fi | |
if [ ! -z $NOTIFY_ANDROID ]; then | |
notify-my-android -k "$NMA_KEY" -e "$NOTIFY_TITLE" -d "$NOTIFY_BODY" -a "${0##*/}" -p ${NOTIFY_PRIORITY:-0} | |
fi | |
if [ ! -z $NOTIFY_IOS ]; then | |
ruby -e " | |
require 'prowl' | |
Prowl.add(:apikey => '$PROWL_KEY', :event =>'$NOTIFY_TITLE', :description => '$NOTIFY_BODY', :application => '${0##*/}', :priority => ${NOTIFY_PRIORITY:-0}) | |
" | |
# with prowl of golang | |
# prowl send "$NOTIFY_TITLE" "$NOTIFY_BODY" -a "${0##*/}" -p ${NOTIFY_PRIORITY:-0} | |
fi | |
if [ ! -z $NOTIFY_MAC ]; then | |
/usr/local/bin/terminal-notifier -title "$NOTIFY_TITLE" -message "$NOTIFY_BODY" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment