The officially official Devuan Forum!

You are not logged in.

#1 2024-01-26 23:06:56

The-Amnesiac-Philosopher
Member
Registered: 2023-08-24
Posts: 432  

Simple Countdown Timer

If you're interested in this...

...as the title says, it's a simple countdown timer that I made for myself and my work. You can adjust the times in the code for your own needs. They're pretty self-explanatory. smile

After choosing a timer, you can close the window.

Dependencies: bash yad papirus-icon-theme

If you don't have papirus-icons, the icons may not show up on the GUI due to how they are named. You can change it in the code if needed. Just replace clock-applet-symbolic with your chosen icon's name in the code.

This is what the GUI looks like (on my systems). Click on a timer and close the window. The timer will still count down and sound off when it's finished despite closing the window. wink

2024-01-26-171128-278x360-scrot.png

If using alsa-only (aplay...as shown in the code below), you must use a .wav sound file. If using pulseaudio, you can use just about any type of sound file.

If you're using pulseaudio, replace aplay with paplay (adjust the code to your needs). I know nothing about pipewire, so I'm not sure what would be needed for that. tongue

I didn't make a desktop.file for it; I just have the script in my file manager and execute it when needed. Sorry.

In the code below, you will also need to replace the path to the sound file that you want to use for the alarm.

Warning!!! Whatever sound file you choose, it will play the entire sound file. So, you might want to choose a file that's only a few seconds long. tongue wink

The code...

#!/usr/bin/env bash

yad --form --columns=1 --width=260 --borders=5 --title="Timer" --no-buttons --height=250 --width=270 --window-icon="/usr/share/icons/Papirus-Light/24x24/panel/alarm-clock-panel.svg" --center --text-align=center --text="
Choose a countdown timer.
" \
--field="  1 Minute!clock-applet-symbolic":fbtn "bash -c 'sleep 1m ; aplay /home/tap/Music/acdc.wav'" \
--field="  3 Minutes!clock-applet-symbolic":fbtn "bash -c 'sleep 3m ; aplay /home/tap/Music/acdc.wav'" \
--field="  15 Minutes!clock-applet-symbolic":fbtn "bash -c 'sleep 15m ; aplay /home/tap/Music/acdc.wav'" \
--field="  30 Minutes!clock-applet-symbolic":fbtn "bash -c 'sleep 30m ; aplay /home/tap/Music/acdc.wav'" \
--field="  45 Minutes!clock-applet-symbolic":fbtn "bash -c 'sleep 45m ; aplay /home/tap/Music/acdc.wav'" \
--field="  60 Minutes!clock-applet-symbolic":fbtn "bash -c 'sleep 60m ; aplay /home/tap/Music/acdc.wav'" \

Offline

#2 2024-01-27 01:46:13

golinux
Administrator
Registered: 2016-11-25
Posts: 3,336  

Re: Simple Countdown Timer

You are too clever!

Offline

#3 2024-01-27 02:37:13

The-Amnesiac-Philosopher
Member
Registered: 2023-08-24
Posts: 432  

Re: Simple Countdown Timer

Thanks, but I won't remember what I did tomorrow... tongue

Offline

#4 2024-01-27 04:03:58

golinux
Administrator
Registered: 2016-11-25
Posts: 3,336  

Re: Simple Countdown Timer

Memory is just detritus that clogs the mind . . . there is only the present moment . . . wink

Offline

#5 2024-01-27 11:29:16

The-Amnesiac-Philosopher
Member
Registered: 2023-08-24
Posts: 432  

Re: Simple Countdown Timer

golinux wrote:

Memory is just detritus that clogs the mind

detritus

If I were to use that word, I'd pillage and plunder it and make it detritusimus  big_smile  tongue

Offline

#6 2024-01-27 12:45:32

swanson
Member
Registered: 2020-04-22
Posts: 107  

Re: Simple Countdown Timer

Nice script!!! Thank You!

If you want a different theme/look you can add this at the top of the script:

export GTK_THEME="Clearlooks-Phenix-Sapphire"

Of course, chosen theme is up to taste. Or no taste. smile

Offline

#7 2024-01-27 14:18:50

The-Amnesiac-Philosopher
Member
Registered: 2023-08-24
Posts: 432  

Re: Simple Countdown Timer

wink

Offline

#8 2024-02-05 10:53:28

swanson
Member
Registered: 2020-04-22
Posts: 107  

Re: Simple Countdown Timer

I've modified the yad script a bit, to also pop-op a countdown timer, so as to know when it's finished.
But, I can not get the code to pass a variable to the next script. I've tried a bunch of stuff like several different kinds of single AND double quotes. I've tried to define the variable TIME and and then read it in in the next script, but it all seems to be above my pay grade (or IQ rather). smile

My altered code:
snip...

--field="   3 Minutes!/home/USER/alarm_96_icon.png":fbtn "bash -c '/home/USER/bin/newtimerwindow3 &  sleep 3m ; aplay /home/USER/alarm-1000.wav'" \

...end snip.

I would like to pass the variable TIME to this script:

#!/bin/bash
##script to open new countdown from newtimer script (yad)

xterm -fa 'Monospace' -fs 48 -geometry 20x4 -e 'bash -c "/home/USER/bin/countdowntimer 3"

Instead of "..countdowntimer 3", I've tested "..countdowntimer $TIME" - no luck.

As you see, it's all very crude, but fun and maybe even a bit functional.

Crude example:

--field="   3 Minutes!/home/USER/alarm_96_icon.png":fbtn "bash -c 'TIME=3 & /home/USER/bin/newtimerwindow &  sleep 3m ; aplay /home/USER/alarm-1000.wav'" \

In the receiving script I use $TIME , but it throws everything off, and nothing opens or happens. Like this:

cat bin/countdowntimer
#!/bin/bash

hour=0
## min="$1"
min="$TIME" 
sec=0
        while [ $hour -ge 0 ]; do
                 while [ $min -ge 0 ]; do
                         while [ $sec -ge 0 ]; do
                                 echo -ne "$hour:$min:$sec\033[0K\r"
                                 let "sec=sec-1"
                                 sleep 1
                         done
                         sec=59
                         let "min=min-1"
                 done
                 min=59
                 let "hour=hour-1"
         done

Last edited by swanson (2024-02-05 10:57:39)

Offline

#9 2024-02-06 16:16:07

stultumanto
Member
Registered: 2023-12-12
Posts: 68  

Re: Simple Countdown Timer

I think the problem is you put a '&' on the command line between setting the variable and executing your script. I tested it myself. I created a minimal test script:

#!/usr/bin/bash
xterm -e "bash -c \"echo $TIME; read\""

Then I ran it like this:

$ TIME=3 countdown.sh

and it opened an xterm window and printed the number '3'.
Then I ran it your way, like this:

$ TIME=3 & countdown.sh

And it opened an empty window. I think when you insert a '&' it breaks up the simple command and makes it into two commands, so the variable is no longer set in the environment for the second command. It shouldn't be a problem to take out the '&' because setting a variable is non-blocking.

Offline

#10 2024-02-08 09:44:50

swanson
Member
Registered: 2020-04-22
Posts: 107  

Re: Simple Countdown Timer

@stultumanto ahh, thank you! Now I've got something to do this snowy day too! smile

Offline

#11 2024-05-03 16:18:04

swanson
Member
Registered: 2020-04-22
Posts: 107  

Re: Simple Countdown Timer

Philosopher Amnesiac wrote:

Warning!!! Whatever sound file you choose, it will play the entire sound file. So, you might want to choose a file that's only a few seconds long.

I learned a new bash command today - 'trap' . And to make the sound stop playing when you close the timer window you can add:

trap 'killall aplay' EXIT

at the beginning of the original script.

Offline

#12 2024-07-21 15:41:16

bai4Iej2need
Member
From: Ortenau
Registered: 2021-04-25
Posts: 117  

Re: Simple Countdown Timer

the oneliner

user@host ~ % sleep 60 ; echo "\a"  & 

should do, whatever you need
60 is time in seconds so put 3600 for an hour

with the & you can close the terminal

Last edited by bai4Iej2need (2024-07-21 15:42:25)


The devil, you know, is better than the angel, you don't know. by a British Citizen, I don't know too good.
One generation abandons the enterprises of another like stranded vessels. By Henry David Thoreau, WALDEN, Economy. Line 236 (Gutenberg text Version)
broken by design :
https://bugs.debian.org/cgi-bin/bugrepo … bug=958390

Offline

Board footer