Using YAD Simple Progress Bar

interpretive language scripts


Moderator: Forum moderators

User avatar
wizard
Posts: 2169
Joined: Sun Aug 09, 2020 7:50 pm
Location: Oklahoma, USA
Has thanked: 2980 times
Been thanked: 799 times

Using YAD Simple Progress Bar

Post by wizard »

YAD Simple Progress Bar

Needed a progress bar for a bash script and found that YAD had an option for it. This code found on the web was really helpful. It uses a for loop and pipes the loop count into YAD to increment the bar and also show the count number, when run you get this:

example1.jpg
example1.jpg (5.24 KiB) Viewed 8578 times

Code: Select all

#!/bin/bash
for ((i=1; i<=100; i++)) {
    echo $i
    echo "# $((i))%"
    sleep 0.5
} | yad --progress \
  --text="Progress demo..." \
  --width=300 \
  --button=yad-cancel \
  --auto-kill

Notice that the bar also shows "21%", which is a bit deceiving since the only thing it is measuring is the loop count and the percentage of the bar that is completed. The maximum "count" for the bar is 100 and this appears to be hard coded in YAD. When the count reaches 100 the bar is complete (stops).

To make the bar more meaningful, changes these:

-i<=300 (increase upper loop limit to run longer)
-echo "# $((i))" (remove % from count display)
-sleep 1 (makes each loop 1 second)

When run you get this:

example2.jpg
example2.jpg (5.45 KiB) Viewed 8578 times

Again, the bar will stop at 100, but the count display will continue to increase. With sleep 1 the count is now time in seconds and represents elapsed time. Much more meaningful.

Now with a little more code we can make the bar loop while the count increases, this gives the user a continually moving bar. This is visually better than example 2.

example3.gif
example3.gif (150.2 KiB) Viewed 8578 times

Note in this code example the loop upper limit (-i<=500) really has no effect as long as it is greater than 100.

The last part of this code is how to apply the bar to a running process. Just put your process code in the "#do commands" section (replace the sleep 30 line).

Thanks to @rcrsn51 for help in determining the best way to end the bar code.

Code: Select all

#! /bin/bash
#250210
#pseudo progress, actually just a timer
#author: wizard on the Puppy Linux Forum
#this loops the bar from 1-100 until killed

#start counting and progress bar
for ((i=1; i<=500; i++)) {
    if [[ $i = 100 ]];then
      i2=$i3 
      i=1
    fi
    i3=$(($i2 + $i))
    echo $i
    echo "# $((i3))"  #this will show number in the bar
    sleep .1 #change this to 1 to show seconds

} | yad --title="Wait" \
        --progress \
        --text="Extracting...time" \
        --width=400 \
        --no-buttons &
PID=$!

#do commands or process, progress bar will run until these complete
sleep 30 #this can be any process or set of commands

#end the progress bar and close yad dialog
sleep 2
kill $PID

wizard

Big pile of OLD computers

User avatar
rcrsn51
Posts: 1486
Joined: Sun Aug 23, 2020 4:26 pm
Been thanked: 424 times

Re: Using YAD Simple Progress Bar

Post by rcrsn51 »

Here is a variation that looks more like a clock.

Code: Select all

#!/bin/sh

SEC=0; MIN=0
while [ 1 ]; do
 echo $((SEC*10/6))
 echo "#$MIN min $SEC sec"
 sleep 1
 ((SEC++))
 [ $SEC -eq 60 ] && SEC=0 && ((MIN++))
done | yad --center --progress \
  --text="Timer" \
  --width=300 \
  --button=Cancel \
  --auto-kill &

PID=$!
sleep 75 #put commands here
kill $PID
User avatar
wizard
Posts: 2169
Joined: Sun Aug 09, 2020 7:50 pm
Location: Oklahoma, USA
Has thanked: 2980 times
Been thanked: 799 times

Re: Using YAD Simple Progress Bar

Post by wizard »

@rcrsn51

Nice work, knew it could be done, just hadn't figured it out yet.

min-sec.jpg
min-sec.jpg (3.65 KiB) Viewed 8463 times

Thanks
wizard

Big pile of OLD computers

User avatar
rcrsn51
Posts: 1486
Joined: Sun Aug 23, 2020 4:26 pm
Been thanked: 424 times

Re: Using YAD Simple Progress Bar

Post by rcrsn51 »

Here is the hours-minutes-seconds version.

Code: Select all

#!/bin/sh

SEC=0; MIN=0; HR=0
while [ 1 ]; do
 echo $((SEC*10/6))
 echo "#$HR hr $MIN min $SEC sec"
 sleep 1
 ((SEC++))
 [ $SEC -eq 60 ] && SEC=0 && ((MIN++))
 [ $MIN -eq 60 ] && MIN=0 && ((HR++))
done | yad --center --progress \
  --text="Timer" \
  --width=300 \
  --button=Cancel \
  --auto-kill &

PID=$!
sleep 75 #put commands here
kill $PID
User avatar
wizard
Posts: 2169
Joined: Sun Aug 09, 2020 7:50 pm
Location: Oklahoma, USA
Has thanked: 2980 times
Been thanked: 799 times

Re: Using YAD Simple Progress Bar

Post by wizard »

@rcrsn51

Like this part

Code: Select all

[ $SEC -eq 60 ] && SEC=0 && ((MIN++))

Maybe could have done it in 5 code lines :lol: :lol:

wizard

Big pile of OLD computers

User avatar
rcrsn51
Posts: 1486
Joined: Sun Aug 23, 2020 4:26 pm
Been thanked: 424 times

An Xdialog Progress Timer

Post by rcrsn51 »

Code: Select all

#!/bin/sh

XdialogTimer ()
{
rm -f /tmp/TimerFlag
SEC=0; MIN=0
while [ 1 ]; do
 echo -e "XXX\nWorking ... $MIN min $SEC sec\nXXX"
 sleep 1
 [ -f /tmp/TimerFlag ] && break  #stop timer when flag file is detected
 ((SEC++))
 [ $SEC -eq 60 ] && SEC=0 && ((MIN++))
done | Xdialog --no-buttons --title " " --info 0 4 30 0
}
export -f XdialogTimer

XdialogTimer &
sleep 10 #put commands here
touch /tmp/TimerFlag #to stop the timer
Last edited by rcrsn51 on Fri Feb 14, 2025 5:47 pm, edited 2 times in total.
Clarity
Posts: 4234
Joined: Fri Jul 24, 2020 10:59 pm
Has thanked: 1814 times
Been thanked: 569 times

Re: Using YAD Simple Progress Bar

Post by Clarity »

Is this helpful should Xdialong not be in the system?

Code: Select all

#!/bin/sh

# Progress-Timer developed by Puppy Linux Forum developer RCRSN51
#

XdialogTimer () {
  SEC=0; MIN=0
  while [ 1 ]; do
    echo -e "Working ... $MIN min $SEC sec"
    sleep 1
    ((SEC++))
    [ $SEC -eq 60 ] && SEC=0 && ((MIN++))
  done | Xdialog --no-buttons --title " " --info 0 4 30 0 &
}

if ! command -v Xdialog &> /dev/null; then
  echo "Xdialog is not installed. Please install it."
  exit 1
fi

XdialogTimer
PID=$!
sleep 10 # Put commands here
kill $PID
some1
Posts: 100
Joined: Wed Aug 19, 2020 4:32 am
Has thanked: 19 times
Been thanked: 22 times

Re: Using YAD Simple Progress Bar

Post by some1 »

Clarity wrote: Thu Feb 13, 2025 5:36 pm

Is this helpful

@Clarity :No!

Clarity
Posts: 4234
Joined: Fri Jul 24, 2020 10:59 pm
Has thanked: 1814 times
Been thanked: 569 times

Re: Using YAD Simple Progress Bar

Post by Clarity »

some1 wrote: Fri Feb 14, 2025 1:36 pm

... @Clarity :No!

Could you, @some1, offer either:

  1. Why it doesn't help

  2. OR you have a better solution when the script is run on a system missing a dependency?

  3. OR you see a flaw in the script

  4. Or was this just a "helpful response" that we are missing?

Curious

some1
Posts: 100
Joined: Wed Aug 19, 2020 4:32 am
Has thanked: 19 times
Been thanked: 22 times

Re: Using YAD Simple Progress Bar

Post by some1 »

@Clarity: ?

Clarity
Posts: 4234
Joined: Fri Jul 24, 2020 10:59 pm
Has thanked: 1814 times
Been thanked: 569 times

Re: Using YAD Simple Progress Bar

Post by Clarity »

@some1

OK, I see. You're just joking around with us neither seeking help or offering any.

User avatar
mikewalsh
Moderator
Posts: 6518
Joined: Tue Dec 03, 2019 1:40 pm
Location: King's Lynn, UK
Has thanked: 993 times
Been thanked: 2170 times

Re: Using YAD Simple Progress Bar

Post by mikewalsh »

@rcrsn51 :-

Bill, what's this "--auto-kill" switch I see you using? I've not come across this one before.....and I don't think I've seen it in the yad man pages, either. What does it do?

EDIT:- Nah, scratch that. You're using one of the newer GTK3 builds of YAD, aren't you? The earlier variants>=YAD 0.40.0 don't have this...

Mike. :?

User avatar
rcrsn51
Posts: 1486
Joined: Sun Aug 23, 2020 4:26 pm
Been thanked: 424 times

Re: Using YAD Simple Progress Bar

Post by rcrsn51 »

mikewalsh wrote: Sat Feb 15, 2025 12:14 am

what's this "--auto-kill" switch I see you using?

You'll have to ask wizard - I just took it out of his code. I don't use yad much myself.

BTW, the technique of stopping the timer with PIDs is rather limited. It may not work if you drop the code into a larger project.

Look at my revised code for the Xdialog Progress Timer. I have replaced the PID with a flag file. This is a more robust method.

User avatar
wizard
Posts: 2169
Joined: Sun Aug 09, 2020 7:50 pm
Location: Oklahoma, USA
Has thanked: 2980 times
Been thanked: 799 times

Re: Using YAD Simple Progress Bar

Post by wizard »

@mikewalsh

what's this "--auto-kill" switch I see you using?

--auto-kill works in conjunction with the --button=yad-cancel, just eliminates writing "if" or "case" logic to kill when the cancel button is clicked.

wizard

Big pile of OLD computers

User avatar
mikewalsh
Moderator
Posts: 6518
Joined: Tue Dec 03, 2019 1:40 pm
Location: King's Lynn, UK
Has thanked: 993 times
Been thanked: 2170 times

Re: Using YAD Simple Progress Bar

Post by mikewalsh »

wizard wrote: Sat Feb 15, 2025 2:03 am

@mikewalsh

what's this "--auto-kill" switch I see you using?

--auto-kill works in conjunction with the --button=yad-cancel, just eliminates writing "if" or "case" logic to kill when the cancel button is clicked.

wizard

Ah! Fair do's, mate. I'd not come across it before, that's all. That's summat new I've learnt today....

Cheers! :thumbup:

Mike. ;)

User avatar
mikewalsh
Moderator
Posts: 6518
Joined: Tue Dec 03, 2019 1:40 pm
Location: King's Lynn, UK
Has thanked: 993 times
Been thanked: 2170 times

Re: Using YAD Simple Progress Bar

Post by mikewalsh »

rcrsn51 wrote: Sat Feb 15, 2025 12:22 am
mikewalsh wrote: Sat Feb 15, 2025 12:14 am

what's this "--auto-kill" switch I see you using?

You'll have to ask wizard - I just took it out of his code. I don't use yad much myself.

BTW, the technique of stopping the timer with PIDs is rather limited. It may not work if you drop the code into a larger project.

Look at my revised code for the Xdialog Progress Timer. I have replaced the PID with a flag file. This is a more robust method.

@rcrsn51 :-

Mm-hm. I've adopted jrb's method for doing stuff when I put things together - kind of like the over-riding principle that's always been behind Unix & Linux, right from the early days.......do one thing, and do it to the best of your ability. So I tend to have one main script, which then calls a whole bunch of other small scripts as and when any 'function' is required.

Some think it's a 'messy', untidy way of doing things. But it works for me.....works very well, in fact. Perhaps it shows a lack of experience.....I couldn't say. Certainly, I have a LONG way to go yet.

I think it's probably fair to say that the majority of folks tend to stick with that which does what they want, in the way that they want.

(*shrug...*)

Mike. ;)

Burunduk
Posts: 268
Joined: Thu Jun 16, 2022 6:16 pm
Has thanked: 7 times
Been thanked: 135 times

Re: Using YAD Simple Progress Bar

Post by Burunduk »

Code: Select all

#!/bin/bash

s=0
while :; do
  printf '%d\n#%02d h %02d m %02d s\n' $((s%60*10/6)) $((s/3600)) $((s/60%60)) $((s++%60))
  sleep 1
done | yad --center --progress --text=timer

or

Code: Select all

#!/bin/bash

st=$(date +%s)
while :; do
  s=$(($(date +%s)-st))
  echo $((s%60*10/6))
  date -ud @$s +\#%T
  sleep 1
done | yad --center --progress --text=timer

Some observations:

It seems the --auto-kill option does nothing here (still Fossapup 9.5) but...

this script will hang:

Code: Select all

#!/bin/bash

while :; do uname; done | head

while this one will stop:

Code: Select all

#!/bin/bash

while :; do uname; echo; done | head

My guess is when a built-in command (echo or printf) tries to write to a closed pipe, bash notices it and terminates the loop.
But when an external command does the same, it's not the bash's business and the loop continues.

This kind of confirms that.

User avatar
MochiMoppel
Posts: 1343
Joined: Mon Jun 15, 2020 6:25 am
Location: Japan
Has thanked: 22 times
Been thanked: 521 times

Re: Using YAD Simple Progress Bar

Post by MochiMoppel »

Burunduk wrote: Sun Feb 16, 2025 12:21 pm

Code: Select all

#!/bin/bash

s=0
while :; do
  printf '%d\n#%02d h %02d m %02d s\n' $((s%60*10/6)) $((s/3600)) $((s/60%60)) $((s++%60))
  sleep 1
done | yad --center --progress --text=timer

or

Code: Select all

#!/bin/bash

st=$(date +%s)
while :; do
  s=$(($(date +%s)-st))
  echo $((s%60*10/6))
  date -ud @$s +\#%T
  sleep 1
done | yad --center --progress --text=timer

or

Code: Select all

#!/bin/bash
SECONDS=0
while :; do
  date -ud @$SECONDS +$((SECONDS%60*10/6))$'\n#%T'
  sleep 1
done | yad --center --progress --text=timer
User avatar
fredx181
Posts: 3385
Joined: Tue Dec 03, 2019 1:49 pm
Location: holland
Has thanked: 437 times
Been thanked: 1484 times
Contact:

Re: Using YAD Simple Progress Bar

Post by fredx181 »

Clarity wrote: Thu Feb 13, 2025 5:36 pm

Is this helpful should Xdialong not be in the system?

Code: Select all

#!/bin/sh

# Progress-Timer developed by Puppy Linux Forum developer RCRSN51
#

XdialogTimer () {
  SEC=0; MIN=0
  while [ 1 ]; do
    echo -e "Working ... $MIN min $SEC sec"
    sleep 1
    ((SEC++))
    [ $SEC -eq 60 ] && SEC=0 && ((MIN++))
  done | Xdialog --no-buttons --title " " --info 0 4 30 0 &
}

if ! command -v Xdialog &> /dev/null; then
  echo "Xdialog is not installed. Please install it."
  exit 1
fi

XdialogTimer
PID=$!
sleep 10 # Put commands here
kill $PID

I wonder if you actually tested that code, if you did, you'd probably found that it doesn't work as expected.
In case you didn't test it, it's a useless post, shame on you then !

Burunduk
Posts: 268
Joined: Thu Jun 16, 2022 6:16 pm
Has thanked: 7 times
Been thanked: 135 times

Re: Using YAD Simple Progress Bar

Post by Burunduk »

MochiMoppel wrote: Sun Feb 16, 2025 1:54 pm

or

Code: Select all

#!/bin/bash
SECONDS=0
while :; do
  date -ud @$SECONDS +$((SECONDS%60*10/6))$'\n#%T'
  sleep 1
done | yad --center --progress --text=timer

Ah, yes!

Code: Select all

#!/bin/bash
# or busybox ash

s=0
while :; do
  date -ud @$s +\#%T
  echo $((s++%60*10/6))
  sleep 1
done | yad --center --progress --text=timer

(As I said, without echo it doesn't stop when yad quits.)

Edit: OK, --auto-kill option does nothing when the "close" button is clicked. When "x" is used, it works.

So...

Code: Select all

#!/bin/busybox ash

s=0
while :; do
  date -ud @$s +\#%T%n$((s++%60*10/6))
  sleep 1
done | yad --center --progress --text=timer --auto-kill --no-buttons

or MochiMoppel's variant with SECONDS for bash.

Clarity
Posts: 4234
Joined: Fri Jul 24, 2020 10:59 pm
Has thanked: 1814 times
Been thanked: 569 times

Re: Using YAD Simple Progress Bar

Post by Clarity »

@fredx181 yes, I was offering it as a guide for an improvement. There are various ways to test for Xdialog presence. That guide is not good.

Here's another approach as a guide. (BTW: I admittedly am not a great script coder. Thus if anyone sees improvement for a test, I welcome it)

My latest guide

Code: Select all

#!/bin/bash

# Function to check if Xdialog is installed
is_xdialog_installed() {
  if command -v xdialog >/dev/null 2>&1; then
    return 0  # Xdialog is installed
  else
    return 1  # Xdialog is not installed
  fi
}

XdialogTimer () {
  # Check if Xdialog is installed *inside* the function
  if ! is_xdialog_installed; then
    echo "Error: Xdialog is not installed. Timer cannot start."
    return 1 # Indicate an error to the caller
  fi

  rm -f /tmp/TimerFlag
  SEC=0; MIN=0
  while [ 1 ]; do
    echo -e "XXX\nWorking ... $MIN min $SEC sec\nXXX"
    sleep 1
    [ -f /tmp/TimerFlag ] && break #stop timer when flag file is detected
    ((SEC++))
    [ $SEC -eq 60 ] && SEC=0 && ((MIN++))
  done | Xdialog --no-buttons --title " " --info 0 4 30 0
}
export -f XdialogTimer

# Check before calling the function
if is_xdialog_installed; then
  XdialogTimer &
  sleep 10 #put commands here
  touch /tmp/TimerFlag #to stop the timer
else
  echo "Error: Xdialog is not installed. Script cannot run."
  exit 1
fi
User avatar
wizard
Posts: 2169
Joined: Sun Aug 09, 2020 7:50 pm
Location: Oklahoma, USA
Has thanked: 2980 times
Been thanked: 799 times

Re: Using YAD Simple Progress Bar

Post by wizard »

@Clarity

The intent of this topic was to show a simple and basic code example for implementiing a YAD progress bar, something not found on the web.

When searching the web for code examples nothing is more frustrating than an overcomplicated answer to a simple question. i.e.,

Norm Newbie question: How do I get bash to print "Hello World" in a terminal screen?

Bobby Bash expert: Well that's easy Norm, and here's how to implement it using a three dimensional array.

Error trapping as you suggest may be necessary, and worth mentioning, but the decision of how or if can be made by the user to suit the application. In this particular case, which is running a GUI, the error would likey not be communicated just by echoing to the console.

My opinion.

wizard

Big pile of OLD computers

Clarity
Posts: 4234
Joined: Fri Jul 24, 2020 10:59 pm
Has thanked: 1814 times
Been thanked: 569 times

Re: Using YAD Simple Progress Bar

Post by Clarity »

hello @wizard
I am not trying to depart from the theme. I also mentioned I am NOT a coding specialist at an length. I am just bringing up that for some Linux systems the Xdialog may not be present and was offering an idea to be taken further...if important.

I believe the Progress bar is a 'great' contribution. But am wondering how less knowledgeable Linux users must frustrate in use, while "asking" if its worthwhile to somehow make them aware should the app dependency not be present in their system. This is a script; not a PET where a dependency is resolved.

Its not a "big deal". And does not warrant any attentions if we are happy.

I have no problem, thus far.

User avatar
fredx181
Posts: 3385
Joined: Tue Dec 03, 2019 1:49 pm
Location: holland
Has thanked: 437 times
Been thanked: 1484 times
Contact:

Re: Using YAD Simple Progress Bar

Post by fredx181 »

Clarity wrote: Sun Feb 16, 2025 10:33 pm

@fredx181 yes, I was offering it as a guide for an improvement. There are various ways to test for Xdialog presence. That guide is not good.

Here's another approach as a guide. (BTW: I admittedly am not a great script coder. Thus if anyone sees improvement for a test, I welcome it)

My latest guide

Code: Select all

#!/bin/bash

# Function to check if Xdialog is installed
is_xdialog_installed() {
  if command -v xdialog >/dev/null 2>&1; then
    return 0  # Xdialog is installed
  else
    return 1  # Xdialog is not installed
  fi
}

XdialogTimer () {
  # Check if Xdialog is installed *inside* the function
  if ! is_xdialog_installed; then
    echo "Error: Xdialog is not installed. Timer cannot start."
    return 1 # Indicate an error to the caller
  fi

  rm -f /tmp/TimerFlag
  SEC=0; MIN=0
  while [ 1 ]; do
    echo -e "XXX\nWorking ... $MIN min $SEC sec\nXXX"
    sleep 1
    [ -f /tmp/TimerFlag ] && break #stop timer when flag file is detected
    ((SEC++))
    [ $SEC -eq 60 ] && SEC=0 && ((MIN++))
  done | Xdialog --no-buttons --title " " --info 0 4 30 0
}
export -f XdialogTimer

# Check before calling the function
if is_xdialog_installed; then
  XdialogTimer &
  sleep 10 #put commands here
  touch /tmp/TimerFlag #to stop the timer
else
  echo "Error: Xdialog is not installed. Script cannot run."
  exit 1
fi

Running this tells me that Xdialog is not installed, but it is on my system !
Changing this line (5) if command -v xdialog >/dev/null 2>&1; then to this: if command -v Xdialog >/dev/null 2>&1; then fixes it.
(Xdialog with uppercase 'X')

Burunduk
Posts: 268
Joined: Thu Jun 16, 2022 6:16 pm
Has thanked: 7 times
Been thanked: 135 times

Re: Using YAD Simple Progress Bar

Post by Burunduk »

Not helpful, just another option...

Code: Select all

#!/bin/bash

for ((i=0; i<=100; i+=5)); do
  echo $i
  sleep 1
done | Xdialog --title Unpackit --gauge "Extracting..." 5 30
User avatar
rcrsn51
Posts: 1486
Joined: Sun Aug 23, 2020 4:26 pm
Been thanked: 424 times

Re: Using YAD Simple Progress Bar

Post by rcrsn51 »

According to the Xdialog documentation, the gauge widget is intended to work this way: the process running in the backend of the pipe will be the actual task you want to perform, not just a counter. That process will know how much of the task has been completed, and can send that info through the pipe to the widget. So the widget knows exactly when the task has finished and can terminate cleanly.

See Fred's example here. Notice how much work it took to extract the progress information from the mksquashfs process.

But wizard wants a more general-purpose timer widget that can run independently in a subshell and be controlled from the foreground. That's a little trickier to manage because the foreground process needs a way to communicate with the timer other than through the pipe.

The $! PID may not work as expected because it needs to kill two jobs running in the background - the Xdialog widget and the infinite counter loop.

[Edit] I wonder if this could be done through a named pipe?
[Edit-Edit] This may be milliseconds more efficient than using a simple flag file.

Code: Select all

XdialogTimer ()
{
mkfifo /tmp/TimerPipe 2>/dev/null
exec 7<>/tmp/TimerPipe
SEC=0
while : ; do
 echo -e "XXX\nScanning ... $SEC sec\nXXX"
 read -u 7 -t 1 && break  #wait 1 sec to get a stop signal from the fifo pipe
 ((SEC++))
done | Xdialog --no-buttons --title " " --info 0 4 30 0
}
export -f XdialogTimer

XdialogTimer &
sleep 10
echo > /tmp/TimerPipe #send signal to stop the timer
Last edited by rcrsn51 on Mon Feb 24, 2025 1:35 pm, edited 11 times in total.
some1
Posts: 100
Joined: Wed Aug 19, 2020 4:32 am
Has thanked: 19 times
Been thanked: 22 times

Re: Using YAD Simple Progress Bar

Post by some1 »

Just a quickie - hope it works :)

Code: Select all

#!/bin/bash

set -m
  (       
    SECONDS=0
    while : ; do
    TZ=UTC printf '%d\n#%(%T)T\n'   $((SECONDS%60*10/6)) $SECONDS 
           #@MM#date -ud @$SECONDS +$((SECONDS%60*10/6))$'\n#%T' 
          
    #printf '%d\n#%(%H h %M m %S s)T\n' $((SECONDS%60*10/6)) $SECONDS  
      sleep 1
    done | yad --title 'ẗimer'  --center --progress  --text='pkill gets me in 19 seconds' --no-buttons  --vertical --rtl --pulsate 101
    ) &
    PID=$!
 
  
    
    sleep 19  ##do funky stuff here untill killing time
    pkill -P $PID   #with set -m    
   # kill -- -$PID  #with set -m
    
     
  
 SECS=$SECONDS
  
 echo "You did funky stuff of: $SECS seconds duration "
 echo "Timer died by pkill  at " $((SECS%60*10/6)) "percent of bar"
   
    exit
User avatar
rcrsn51
Posts: 1486
Joined: Sun Aug 23, 2020 4:26 pm
Been thanked: 424 times

Re: Using YAD Simple Progress Bar

Post by rcrsn51 »

some1 wrote: Wed Feb 19, 2025 3:07 pm

pkill -P $PID

I tested this and it definitely does a better job of cleaning up all the processes connected to the timer.

User avatar
rcrsn51
Posts: 1486
Joined: Sun Aug 23, 2020 4:26 pm
Been thanked: 424 times

Re: Using YAD Simple Progress Bar

Post by rcrsn51 »

Here's an example of an Xdialog gauge widget being controlled by a fifo.

Code: Select all

XdialogGauge ()
{
mkfifo /tmp/TimerPipe 2>/dev/null
exec 7<>/tmp/TimerPipe
SEC=0
while : ; do
 echo $((SEC*10))
 read -u 7 -t 1 && break
 ((SEC++))
 [ $SEC -gt 10 ] && SEC=1
done | Xdialog --no-buttons --title " " --gauge "Working ..." 4 30 0
}
export -f XdialogGauge

XdialogGauge &
sleep 32
echo > /tmp/TimerPipe
User avatar
wizard
Posts: 2169
Joined: Sun Aug 09, 2020 7:50 pm
Location: Oklahoma, USA
Has thanked: 2980 times
Been thanked: 799 times

Re: Using YAD Simple Progress Bar

Post by wizard »

@rcrsn51

What would be the advantage of using this code? Will it accurately gauge the running process completion?

Thanks
wizard

Big pile of OLD computers

Post Reply

Return to “Scripts”