FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Debian > Debian User

 
 
LinkBack Thread Tools
 
Old 01-04-2011, 03:02 PM
Hugo Vanwoerkom
 
Default looking for a clock, minimum and can play sound

Camaleón wrote:

On Tue, 04 Jan 2011 20:06:30 +0800, Zhang Weiwu wrote:


Hello. I am looking for an count-down clock. Features are:


(...)

If you find no aplication that suits your needs, may I suggest a "do-
it-yourself" work? :-)

Dialog (command line ncurses scripting) and xdialog (GUI) can help you
here. It's very easy to use and just basic bash programming skills needed.


Some tutotials with usage samples:



If you get the source of dialog then you will find plenty of examples in
the 'samples' dir.


Funny that you mentioned 'dialog': I just had a run-in with it. I wrote
an app. in 2005 to use the '--form' option of it to fill out a form and
pass the data to a daemon. Come to find out that my dialog script no
longer worked: I got a -1 rc and the message 'Expected 8 parameters and
found only 3'. That message was not very helpful so I got the source and
modified 'dialog.c' to show *what* parameters it found. Turned out that
dialog got tripped up by blanks in the form labels. But how come it ever
worked?


Hugo


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org

Archive: ifvga7$hde$1@dough.gmane.org">http://lists.debian.org/ifvga7$hde$1@dough.gmane.org
 
Old 01-17-2011, 04:53 AM
T o n g
 
Default looking for a clock, minimum and can play sound

On Tue, 04 Jan 2011 13:11:24 +0000, Camaleón wrote:

>> Hello. I am looking for an count-down clock. Features are:
>
> (...)
>
> If you find no aplication that suits your needs, may I suggest a "do-
> it-yourself" work? :-)
>
> Dialog (command line ncurses scripting) and xdialog (GUI) can help you
> here.

The following shell script will work:

--------------------------
#!/bin/sh
sleep $1
beep
-------------------------

name it 'alarm' and 'alarm 30' will alarm you after 30 seconds.





--
Tong (remove underscore(s) to reply)
http://xpt.sourceforge.net/techdocs/
http://xpt.sourceforge.net/tools/


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
Archive: ih0lg8$snu$2@dough.gmane.org">http://lists.debian.org/ih0lg8$snu$2@dough.gmane.org
 
Old 01-17-2011, 06:33 PM
Bob Proulx
 
Default looking for a clock, minimum and can play sound

T o n g wrote:
> The following shell script will work:
>
> --------------------------
> #!/bin/sh
> sleep $1
> beep
> -------------------------
>
> name it 'alarm' and 'alarm 30' will alarm you after 30 seconds.

That works if you know how many seconds to wait. Let's say that it is
Mon, 17 Jan 2011 12:08:08 -0700 and you want an alarm to trigger at
3pm local time at Mon, 17 Jan 2011 15:00:00 -0700. Then you know that
you can sleep for 10312 seconds.

alarm-sleep 10312

That is great. But calculating that value when you are sleepy isn't
for everyone. Instead I would program that into the script to do for
you. Use GNU date's --date extension to calculate the date from a
given date string.

until="3pm"
now=$(date +%s)
then=$(date -d "$until" +%s)
delay=$(( $then - $now ))
sleep $delay

Then you can say something like:

sleep-until-do 3pm some command with args here

Below is a script I call sleep-until-do which sleeps until the given
time and then invokes the given command. I use it to turn on the
radio to listen to the news at the top of the hour. Perhaps you will
find it useful too.

Bob

#!/bin/sh

# Copyright 2009, 2010, 2011 Bob Proulx <bob@proulx.com>
# You may freely use, modify and/or distribute this file.

if [ $# -lt 1 ]; then
echo "Error: Missing time argument" 1>&2
exit 1
fi

if [ $# -lt 2 ]; then
echo "Error: Missing do-command argument" 1>&2
exit 1
fi

until=$1
shift

echo "Info: $until interpreted as:" $(date -R -d "$until")

now=$(date +%s)
then=$(date -d "$until" +%s)
delay=$(( $then - $now ))

if [ $delay -gt 2 ]; then
echo Sleeping $delay seconds...
sleep $delay
else
echo Info: Time has passed.
fi

echo Invoking: "$@"
exec "$@"
 
Old 01-28-2011, 07:03 PM
Camaleón
 
Default looking for a clock, minimum and can play sound

On Tue, 04 Jan 2011 10:02:13 -0600, Hugo Vanwoerkom wrote:

(sorry for resurrecting this thread. I know is a bit old but I remembered
the subject and thought the additional information could help the OP)

> Camaleón wrote:
>> On Tue, 04 Jan 2011 20:06:30 +0800, Zhang Weiwu wrote:
>>
>>> Hello. I am looking for an count-down clock. Features are:
>>
>> (...)
>>
>> If you find no aplication that suits your needs, may I suggest a "do-
>> it-yourself" work? :-)
>>
>> Dialog (command line ncurses scripting) and xdialog (GUI) can help you
>> here. It's very easy to use and just basic bash programming skills
>> needed.
>>
>> Some tutotials with usage samples:
>>
>>
> If you get the source of dialog then you will find plenty of examples in
> the 'samples' dir.
>
> Funny that you mentioned 'dialog': I just had a run-in with it. I wrote
> an app. in 2005 to use the '--form' option of it to fill out a form and
> pass the data to a daemon. Come to find out that my dialog script no
> longer worked: I got a -1 rc and the message 'Expected 8 parameters and
> found only 3'. That message was not very helpful so I got the source and
> modified 'dialog.c' to show *what* parameters it found. Turned out that
> dialog got tripped up by blanks in the form labels. But how come it ever
> worked?

Yep, I also have some scripts that used the ncurses "dialog" and you can
expect some changes between versions (some bugs are fixed and you have to
adjust your old code to get the same job done) :-)

Anyway, I've been recently working on a "enhanced" version of one of that
scripts (now using "zenity" instead "dialog") and had to add kinda
count-down to monitor the time a job gets done. I put here the code excerpt
(is a very short piece of text) just in case the OP is still in the need of
a simple counter (I guess it can be easily adapted to be run with "dialog"):


#!/bin/sh

# A simple count-down with progress bar
# that plays a sound alert once it's over

# Countdown start time (in seconds)
timer=30

# Sound file to play
sound="/usr/share/sounds/ekiga/voicemail.wav"

pbar=0
factor=$(echo "scale=2; 100/$timer" | bc)

(
for (( i=$timer; i>=0; i--)); do
echo $pbar;
echo "#Countdown: $timer seconds left"; timer=$((timer-1)); pbar=$(echo "scale=2; $pbar+$factor" | bc); sleep 1;
done;
aplay $sound 2>&1
) |
zenity
--progress
--auto-close
--title="Countdown"
--text="Countdown: $timer seconds left"

if [ $? = 1 ]; then exit; fi
exit


Greetings,

--
Camaleón


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
Archive: pan.2011.01.28.20.03.39@gmail.com">http://lists.debian.org/pan.2011.01.28.20.03.39@gmail.com
 

Thread Tools




All times are GMT. The time now is 10:17 AM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2007 - 2008, www.linux-archive.org