Published: Mon 11 January 2010
alarm bash scripts
I published a script that lets you set an alarm from the command line,
nice and easy. One thing was lacking though: visual notification of the
alarm, so if you happen to be away from the computer when the alarm
sounds you'll still see the dialog box. To achieve that I've modified
the script, added an extra one, so here's the new and shinier alarm
First, the alarm script:
if [ " $1 " = '' ]
echo "No arguments for for alarm! Supply with time and optionally message
alarm '3pm + 3 day'
alarm 'now + 5 minutes' 'go do ... stuff'
message = "alarm time reached"
[ " $2 " = '' ] && message = $2
if ` echo aplay -q /home/fake51/Downloads/gqold.wav \&\& ddisplay \" $message \" | at $1 2> \& 1 > /dev/null `
echo "Setting alarm failed"
Now, the major difference to the previous script lies in the script
accepting a message, setting a default message, and then using ddisplay
to display a message box.
Now, ddisplay is not a linux command - it's the second part of this
if [ " $1 " = "" ]
export DISPLAY =:0
zenity --warning --text = " $1 "
This script makes use of the zenity command - which basically displays
GTK+ dialogs. The 'warning' option makes zenity display a normal dialog
box on top of everything, while the 'text' option is obviously the text
to display. Hence, pass a text string to ddisplay and you'll get a
dialog box with it - and that's what the first script does, thus playing
the alarm sound and popping up a dialog box when the sound is done.
The reason for adding the extra script is that 'at' schedules commands
to run - so putting the dialog box code in a function in the alarm
script isn't an option. One could try sticking the zenity command
straight in the 'echo' piped to 'at', but to run 'zenity' from a script,
you typically need to set a few environment variables (these are set if
you run zenity straight from the command line, but not necessarily if
run by cron or at). On the plus side, ddisplay can be reused for other
scripts as well, simplifying them.
Proudly powered by
Pelican, which takes great advantage of Python.
The theme is by
Smashing Magazine, thanks!