Six months ago, I set up a Bash alias for a quick and simple notification:
alias beeps='(BEEPS_RET=$? ; ((BEEPS_RET)) && BEEPS=error || BEEPS=generic ; for i in {1..5} ; do (aplay -q /usr/share/sounds/$BEEPS.wav &) >/dev/null ; sleep 1 ; done ; exit $BEEPS_RET)'
Note
In 2015, I am using wave to generate sine wave and play using aplay, as the notification sound, instead of audio files.
It plays an audio file for five times based on what the previous exit status code, and that’s all what this alias does. Now, it has evolved into a function with dzen for visual notification, a snapshot of beeps from bash_helper_func.sh:
######################################################################
# beeps: Providing visual and audio notifications via dzen2 and a wave
# Usage: beeps <message is written here>
# ref: The poor man's notification (old method, audio only)
# https://yjlv.blogspot.com/2012/12/the-poor-mans-notification.html
beeps() {
(( BEEPS_RET=$? )) && BEEPS=error || BEEPS=generic
# subshell'd to get rid of: [JOB#] PID#
(
for i in {1..5}; do
(aplay -q /usr/share/sounds/$BEEPS.wav &) >/dev/null
sleep 1
done &
echo "$@" |
dzen2 -p 10 -fn 'Envy Code R:size=24' -fg '#ff0000' &
)
return $BEEPS_RET
}
It can be used like:
sleep 10m ; beeps 'Pasta is cooked!'
beeps Poor man\'s notification is the best!
When time’s up, five beeps with a 10-second message popping up. The options for dzen are the way I like, so I didn’t add customizable options, just moved the alias code into the function. You can make the visual notification stays forever until a right click on it, but I like it goes away by itself after 10 seconds.
Poor man’s notification is the best!
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.