#!/bin/bash # c 2014 Roland Latour, gpl v2 # Idea: prompt for time, like this: # 9menu -font 9x18 -fg black -bg white -label 'Timer' \ # "30 seconds":'exec echo 30' "1 Minute":'exec echo 60' \ # "3 Minutes":'exec echo 180' "5 Minutes":'exec echo 300' \ # "10 Minutes":'exec echo 600' "30 Minutes":'exec echo 1800' # Syntax: timer [seconds [label]] # parameters are optional # This works: timer minutes*60 label (timer 27*60 Pizza) # for label: use quotes to prevent interpretation by bash for (say) # ampersands or exclamation marks. function blink_status_bar () { (for ((i=1; i<8; i++));do sleep .1;echo 0;sleep .1;echo 100 done) } # if there is a 1st parameter, use it, else assume 3 minutes if test -z "$1"; then LIMIT=180 LABEL="Tea_Timer" else LIMIT=$1 # force mathematical evaluation, for syntax: timer minutes*60 let LIMIT=($LIMIT * 1) # eliminates error message: "integer expression expected" # getting strange results with leading zeros let min=($LIMIT / 60) LABEL=$min"_Minute_Timer" fi # if there is a 2nd parameter, use it as LABEL if test -z "$2"; then true else LABEL=$2 LABEL=`echo $LABEL|sed 's/ /_/g'` fi #=======Start timing========== # parens cause work to be done in a subshell, then piped to zenity ( # relocate yad to 1st workspace wmctrl -d > /dev/null;sleep .2;wmctrl -r $LABEL -t 0 for ((a=$LIMIT; a > 0; a--)); do # compute Hrs/Mins/Secs let hour=($a / 3600) let y=($hour * 60) let min=($a / 60) let min=($min - $y) let y=($y * 60) let z=($min * 60) let sec=($a - $y - $z) if [ $hour -gt 0 ]; then # pad min and sec, ex: "9" to "09", "0" to "00" echo "# Time Left: $hour:`printf "%02.f" $min`:`printf "%02.f" $sec`" else # pad sec, ex: "9" to "09", "0" to "00" echo "# Time Left: $min:`printf "%02.f" $sec`" fi # compute percentage of limit time, update progress bar let y=($LIMIT - $a) let y=($y * 100) let pct=($y / $LIMIT) echo $pct;sleep 0.99 # off by 7 seconds in 3 hours done echo 100;echo "# $LABEL complete" # move yad to current workspace, always-on-top wmctrl -R $LABEL;wmctrl -r $LABEL -b add,above # Notification area beep -f 1000 -n -f 2000 -n -f 1500 & # try linux.png, puppy.png, pumpkin.svg, bart.svg, freebsd.png xcowsay -t 4 --at=1950,200 --image=/home/rolandl/save/images/general/linux.png "$LABEL has completed!" & blink_status_bar #espeak "$LABEL has completed" #aplay -q ~/save/waves/cowbell.wav ) | yad --progress --geometry=220x90+5+300 --image-on-top --title=$LABEL \ --image=/usr/share/icons/Adwaita/32x32/status/appointment-soon-symbolic.symbolic.png \ --auto-kill