Mint Serena 64 bit using the Mate desktop environment. Most of the following scripts will run on this machine, although some have only been tested with the Gnome desktop. Extra software requirements can be met by the Ubuntu and safe PPA repositories. Scripts may be re-written or added to from time to time, the date serves as the version number. Syntax highlighting on these pages is provided by GVim's "Convert to HTML" option.

Simple timer with progress bar.


~/.scripts/progbar-timer.sh.html #!/bin/bash
# Filename: progbar-timer.sh
# Version: 110212
# Author: robz
# Improved from the "Egg Timer" script, a countdown timer with progress bar.
# This one has an indication of time remaining provided by Zenity's progress
# bar function. As usual you'll need to find a sound and icon for the variables
# below, you might find the icon variable is correct, check the directory.

ICON=/usr/share/app-install/icons/kalarm.png              # Existing icon?
SOUND=$HOME/Audio/2tone.wav                               # Your sound pref.

COUNT=$(zenity --title "Egg Timer" --window-icon $ICON --text "No decimals"\
    --entry-text "eg. 10s or 5m or 2h" --entry)           # Input dialogue.
if [ $? = 1 ]; then exit $?; fi

# Determine number of seconds to count down from depending on input suffix.
case "${COUNT: -1}" in
    "S" | "s" ) COUNT=$(echo $COUNT | sed -s "s/[Ss]//") ;;
    "M" | "m" ) COUNT=$(echo $COUNT | sed -s "s/[Mm]//"); ((COUNT*=60)) ;;
    "H" | "h" ) COUNT=$(echo $COUNT | sed -s "s/[Hh]//"); ((COUNT*=3600)) ;;
    *         ) zenity --error --text "<span color=\"red\"><b>\
    \nUse the form of 10s or 5m or 2h\nNo decimals allowed either.</b></span>"
    sh -c "$0"                                            # On error restart.
    exit ;;
esac

START=$COUNT                                              # Set a start point.

until [ "$COUNT" -eq "0" ]; do                            # Countdown loop.
    ((COUNT-=1))                                          # Decrement seconds.
    PERCENT=$((100-100*COUNT/START))                      # Calc percentage.
    echo "#Time remaining$(echo "obase=60;$COUNT" | bc)"  # Convert to H:M:S.
    echo $PERCENT                                         # Outut for progbar.
    sleep 1
done | 
zenity --title "Egg Timer" --progress --percentage=0 --text=""\
    --window-icon=$ICON --auto-close                      # Progbar/time left.
if [ $? = 1 ]; then exit $?; fi
notify-send -i $ICON "Egg Timer > ## TIMES UP ##"         # Attention finish!
/usr/bin/canberra-gtk-play --volume 4 -f $SOUND           # Ding-dong finish!

zenity --notification --window-icon="$ICON"\
    --text "Egg Timer > ## TIMES UP ##"                   # Indicate finished!

7 comments:

Nye said...

love this!

Rob said...

Thanks Nye, your appreciation is appreciated.

Anonymous said...

Best and simple timer for my Ubuntu.

Is possible to put the cont down time in window title, so i will see in taskbar the time remaining?

Rob said...

Sorry Anon but I use Ubuntu 12.10 with the Unity desktop, ie. no taskbar. As far as I can tell Zenity draws it's main window and title once and then just updates the contents within that window.

Ikem said...

A few things I like to mention:

You don't need an absolute path for the icon. Something like "alarm" should be sufficient.

Instead of "/usr/bin/canberra-gtk-play" I suggest to use "aplay".

rho con linux said...

Can't make it run in ubuntu 1404

line 21: "case" is a bad substitution, it says.

:)

Rob said...

Hi rho, not yet running 14.04 still on 13.10 and it runs ok on this, can't help you yet sorry.