Register
It is currently Sat Aug 30, 2014 12:24 pm

Countdown Timer


All times are UTC - 6 hours


Post new topic Reply to topic  [ 3 posts ] 
Author Message
 PostPosted: Wed May 07, 2008 1:42 am   

Joined: Wed May 07, 2008 1:20 am
Posts: 1
I asked on ostatic.com if someone knew of a countdown timer tool. A reply suggested doing this with a script - which I'm not able to myself (yet;-) I don't need anything fancy - just a quick way to enter hours/min/sec and see the time remaining...and some sort of popup/alarm when the countdown finishes. Here is an image of the Windows timer I use.

Thanks


Top
 Profile  
 PostPosted: Wed May 07, 2008 11:26 am   

Joined: Tue Apr 01, 2008 10:19 am
Posts: 49
You could do this in a few ways. Try looking at zenity for a dialog box, and use "at" or "wait" for the timer, depending on your installation. expr and date together can find the time if you need to use wait. at is better, but not installed on all systems.


Top
 Profile  
 PostPosted: Wed May 07, 2008 12:53 pm   
User avatar

Joined: Sun Apr 13, 2008 4:05 am
Posts: 37
Location: /dev/random
there is a mediatation timer i use. which can help you.
it plays the wave files that stored in ~/.meditate to warn
thx flightlessbird for script.
Code:
#!/bin/bash
#http://flightlessbird.vox.com/library/post/meditation-timer.html
#author:  flightlessbird

usage ()
{   
echo -e "\033[1mUsage\033[0m: `basename $0` -slt"
echo '-s [number]          number of stages, eg 5'
echo '-l [time]            length of each stage
                     either in seconds, eg 300
                     or in format MIN:SEC, eg 5:00'
echo '-t [time]            total time for practice
                     either in seconds, eg 1500
                     or in format MIN:SEC, eg 25:00'
echo "-l and -t are not compatible, only one can be used at a time"
}

lengthconvert ()
{
if echo $1 | grep -q :
    then
    MIN=$(echo $1 | sed 's/:.*//')
    SEC=$(echo $1 | sed 's/.*://')
    TOTALLENGTH=$[($MIN*60)+$SEC]
else
    TOTALLENGTH=$1
fi
echo $TOTALLENGTH
}

bell ()
{
play $HOME/.meditate/*.wav &> /dev/null
}

countdown ()
{
TIMER=$1
MAXLEN=${#TIMER}
echo -n "$TIMER"
until [ $TIMER = 0 ]
    do
    sleep 1
    DELENDA=$MAXLEN
    until [ $DELENDA = 0 ]
        do echo -ne "\b"
        let DELENDA-=1
    done
    let TIMER-=1
    echo -n $TIMER
    GAP=$[$MAXLEN-${#TIMER}]
    while [ $GAP -gt 0 ]
        do echo -n " "
        let GAP-=1
    done
done
echo -ne "\n"
}

#default options
STAGES=4
LENGTH=300

while getopts ":s:l:t:h" Option
    do
    case $Option in
        s    ) STAGES="$OPTARG";;
        l    ) LENGTH=$(lengthconvert "$OPTARG");;
        t    ) TOTALTIME=$(lengthconvert "$OPTARG");;
        h    ) usage
              exit;;
        ?    ) badopt="$OPTARG";;
    esac
done

if [ $badopt ]
    then
    echo "ERROR: bad option $badopt"
    exit 3
elif [[ $STAGES -le 0 || $LENGTH -le 0 ]]
    then
    echo "ERROR: invalid options"
    exit 3
elif [[ $TOTALTIME && $LENGTH -ne 300 ]]
    then
    echo "ERROR: incompatible options - -s and -l cannot be used together"
    exit 3
elif [ $TOTALTIME ]
    then
    LENGTH=$[$TOTALTIME/$STAGES]
fi   

COUNTER=1
SECONDS=$[$LENGTH%60]
echo -n "$STAGES stages of $[$LENGTH/60] minutes"
if [ $SECONDS -gt 0 ]
    then
    echo -n ", $SECONDS seconds"
fi
echo " each"

until [ $COUNTER -gt $STAGES ]
    do
    echo "Stage $COUNTER of $STAGES"
    countdown $LENGTH
    bell
    let COUNTER+=1
done

bell

exit


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 12 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP