Last active
February 13, 2016 16:09
-
-
Save fpytloun/4acc181d67d78b47b23b to your computer and use it in GitHub Desktop.
Simple desktop notifications from cli
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
#!/bin/bash | |
# | |
# Simply make some noise to notify user | |
# Usage: | |
# alarm.sh [message] | |
# echo alarm.sh | at 15:30 | |
# | |
## Required variables | |
export DISPLAY=${DISPLAY:-":0.0"} | |
ALARM_MSG=${ALARM_MSG:-${1:-"$(date)"}} | |
ALARM_SND=${ALARM_SND:-"/usr/share/games/hedgewars/Data/Sounds/voices/Classic/Hello.ogg"} | |
ALARM_ICO=${ALARM_ICO:-"gtk-dialog-info"} | |
# Fallback for non-existing alarm sound | |
[ ! -f "${ALARM_SND}" ] && ALARM_SND="/usr/share/sounds/gnome/default/alerts/glass.ogg" | |
## Do the alert | |
# First on the console | |
echo -ne '\007' | |
# Try to make some sound | |
if [ -x $(which mplayer) ]; then | |
mplayer --quiet "${ALARM_SND}" >/dev/null & | |
elif [ -x $(which beep) ]; then | |
# Try beep as a last resort | |
beep & | |
fi | |
# Display alert in GUI | |
if [ -x $(which notify-send) ]; then | |
# Desktop notification will be the best | |
notify-send -t 0 -i "${ALARM_ICO}" Alarm -u critical "${ALARM_MSG}" | |
elif [ -x $(which terminal-notifier) ]; then | |
# Mac OS X notification, sometimes gets stuck, so just kill it after few | |
# seconds and ignore | |
( terminal-notifier -sound default -message "${ALARM_MSG}" ) & sleep 3; kill $! | |
elif [ -x $(which gxmessage) ]; then | |
gxmessage -button ok -center "${ALARM_MSG}" | |
elif [ -x $(which xmessage) ]; then | |
xmessage -button ok -center "${ALARM_MSG}" | |
else | |
# Ok, we are screwed now, fallback to shell alert.. | |
echo "[ALARM] ${ALARM_MSG}" | write ${USER} | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment