Simple Desktop Timer With OSD

I needed a really simple timer which would take the number of seconds and play a sound clip. Since I’m into writing Bash scripts these days, I decided do this in Bash. Result is a funky little tool that will get the job done very nicely.

To use the script, you will need a few things other than Bash. You will need mplayer (or you can hack the script to play sounds with something else), and osd_cat to show OSD text. On Arch Linux, osd_cat is part of xosd package. Finally, you will need a sound clip. I got mine from freesound.org (registration required for download, and all clips are creative commons).

#!/bin/bash                                                                    

TIME=$1                                                                        
FONT="-*-fixed-medium-r-*-*-36-*-*-*-*-*-iso8859-*"                            

echo ${TIME} seconds                                                           
echo ${TIME} seconds | osd_cat -p middle -A center -f $FONT -O 2 -d 2 &        
sleep $1                                                                       
echo "Time's up"                                                               
echo "Time's up" | osd_cat -p middle -A center -f $FONT -O 2 &                 
mplayer -really-quiet ~/sounds/abstract_beep_01.wav > /dev/null                
sleep 1                                                                        
mplayer -really-quiet ~/sounds/abstract_beep_01.wav > /dev/null                
sleep 1                                                                        
mplayer -really-quiet ~/sounds/abstract_beep_01.wav > /dev/null                
sleep 1

I hope you find this useful. The reason I have OSD there is I usually keep the headphone on my desk while it’s still plugged in, so sometimes I don’t even hear any sounds. So a big red “Time’s up” over my screen is a helpful cue.