Progress bar fundamentals?

1,746 views
Skip to first unread message

giles holt

unread,
May 15, 2016, 8:17:02 PM5/15/16
to yad-common
Hi,

I'm trying to understand how to use the progress bar properly, I've read other questions in this group but i feel like i'm still missing some fundamentals.

Can i write a script and upon running the script pipe into a yad progress bar? (thats something i've already made an attempt at and failed, but that may just be my poor coding)

If not, how to I use it? throughout the script do I need to repeatedly let yad progress bar have some data input from which its calculates the percentage? if so how etc.


example of what have so far:

~/Scripts/test.sh | yad --progress --pulsat --center --text="Testing..." --button=cancel:0 --auto-kill --auto-close ;;

Many thanks again in advance.


Julio C. Neves

unread,
May 16, 2016, 9:08:30 AM5/16/16
to yad-c...@googlegroups.com
Your script can echo two types of data for the progress bar:
  1. Numbers between 1 and 100 will update the taskbar;
  2. Text lines started with # will be displayed in the bar.
1 good example is worth a 1000 words. Copy paste to the prompt:

for ((i=1; i<=100; i++))
{
    echo $i
    echo "# Remaining $((100-i))% to finish the job"
    sleep 0.2
} | yad --progress --center --text="Testing..." --button=gtk-cancel --auto-kill --auto-close


Abcs,
Julio
@juliobash

P
róximos cursos de Shell
Cidade         Local Período
Rio de Janeiro EDX 0
​7-08/05 e 14-15/05 (Sábados e Domingos)
Dou treinamento de Shell em qualquer cidade.
Para mais detalhes, me mande um e-mail.



--
You received this message because you are subscribed to the Google Groups "yad-common" group.
To unsubscribe from this group and stop receiving emails from it, send an email to yad-common+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

giles holt

unread,
May 16, 2016, 10:22:19 AM5/16/16
to yad-common
This on its own works beautifully, and I have tinkered with it to get it to say the sort of things I want, but as soon as I incorporate it into a script it causes the script to just exit and no progress bar shows. also how can i keep the progress bar up to date with how far along the script is? do i need to break this example down and give each section of the script a pipe into the yad progress bar with the next starting percentage e.g. 1st part of script goes to 20%, next part starts at 20% and goes to 30% etc. Here is an example of what i have (however i want this first bit to make up only 10 % of the progress):


for ((i=1; i<=100; i++))
{
    echo $i
    echo "# Remaining $((100-i))% to finish the job"
    sleep 0.2
} | yad --progress --pulsate --center --percentage=0 --log-expanded --enable-log --width=500 --height=200 --size=fit --text="testing..." --button=cancel:0 --auto-kill --auto-close


FILE=~/"tmp/test.txt"
STRING="S1_L001_"
if [ ! -z $(grep "$STRING" "$FILE") ]
    then
        if [ -f ~/output/output.txt ]
            then
                echo "output already exists, running next
    "
                echo | notify-send "output already exists, running next
    "
        elif [ -f ~/Input/input.txt ]
            then
                echo |  notify-send "input present and not previously run, running now" | echo "input present and not previously run, running now
    "
            else
                echo | notify-send "input required is not present, trying next" | echo "input required is not present, trying next
    "
        fi
fi

giles holt

unread,
May 16, 2016, 10:24:15 AM5/16/16
to yad-common
sorry, just to be clear, when i run the example you gave me it works beautifully, when i incorporate it into my script (example just given) it causes the script to crash

Julio C. Neves

unread,
May 16, 2016, 11:53:43 AM5/16/16
to yad-c...@googlegroups.com
File=tmp/test.txt
String=S1_L001_
Image=/usr/share/icons/gnome/48x48/devices/drive-harddisk.png
grep "$String" "$File" && {
    if [ -f ~/output/output.txt ] && notify-send -i $Image "output.txt" "output already exists, running next"
    if [ -f ~/Input/input.txt ]
    then
        notify-send -i $Image "input.txt" "input present and not previously run, running now" 
    else 
        notify-send -i $Image "input.txt" "input required is not present, trying next" 
    fi
}


Abcs,
Julio
@juliobash

giles holt

unread,
May 16, 2016, 1:02:19 PM5/16/16
to yad-common
Thank you for your help and quick replies, its much appreciated, how you inform the yad progress bar as a script progresses makes much more sense now. but when trying your amendments to my script to incorporate the information required for the progress bar it fails to work and states   syntax error near unexpected token `}' . There must be something within my script thats causing this, but i can't see what. Here is the version i have of what you suggested, with my true full paths etc:

File=~/"program/tmp/Files.txt"
String="name_1.fastq"

Image=/usr/share/icons/gnome/48x48/devices/drive-harddisk.png
grep "$String" "$File" && {
    if [ -f ~/program/output/S1/C.fasta ] && notify-send -i $Image "output.fasta" "output already exists, running next"
    if [ -f ~/Program/Files/*name_1.fastq ]
    then
        notify-send -i $Image "C.fasta" "input present and not previously run, running now"
    else
        notify-send -i $Image "C.fasta" "input required is not present, trying next"
    fi

} | yad --progress --pulsate --center --percentage=0 --log-expanded --enable-log --width=500 --height=200 --size=fit --text="testing..." --button=cancel:0 --auto-kill --auto-close

Julio C. Neves

unread,
May 16, 2016, 1:25:50 PM5/16/16
to yad-c...@googlegroups.com
Sorry, my fault.

Just change:
if [ -f ~/output/output.txt ] && notify-send -i $Image "output.txt" "output already exists, running next"

For:

[ -f ~/output/output.txt ] && notify-send -i $Image "output.txt" "output already exists, running next"

Abcs,
Julio
@juliobash

P
róximos cursos de Shell
Cidade         Local Período
Rio de Janeiro EDX 0
​7-08/05 e 14-15/05 (Sábados e Domingos)
Dou treinamento de Shell em qualquer cidade.
Para mais detalhes, me mande um e-mail.



giles holt

unread,
May 16, 2016, 4:15:04 PM5/16/16
to yad-common
thanks for the reply again.

I’ve removed that ' if ', but it still won't work and is giving the same problem i.e. syntax error near unexpected token `}' . When I remove all if functions, the same problem still occurs. I have no idea why? there must be some kind of problem with the [ -f /full/path ]

Julio C. Neves

unread,
May 16, 2016, 4:52:04 PM5/16/16
to yad-c...@googlegroups.com
This is a bash scripting error and not a yad question so is better discuss it in private. Please send a e-mail to e...@juliao.eu with your code attached.

Abcs,
Julio
@juliobash

giles holt

unread,
May 16, 2016, 5:25:49 PM5/16/16
to yad-common
I haven't solved the problem, but through trial and error i have found that the [ -f ~/output/output.txt ] is what's causing the error: syntax error near unexpected token `}'

I don't know why this is causing the problem

giles holt

unread,
May 16, 2016, 5:27:10 PM5/16/16
to yad-common
Brilliant, thank you, i will do.
Reply all
Reply to author
Forward
0 new messages