display YAD progress bar while finding files

1,908 views
Skip to first unread message

Roelof Berkepeis

unread,
Jan 31, 2017, 8:41:41 AM1/31/17
to yad-common
hello all,

I'm new to YAD and i want to build some application which finds all JPG files (or other) in a folder and its subfolders, display the found file names in a YAD dialog (i'm using --list for this) and perform some string filtering functions on each file name to finally build an SQL statement : this SQL will be written to a file, which the user later can execute to insert these file names (and their dates/sizes/etc) into a database. I somewhat succeeded : the finding process is indeed shown in a YAD list by this script :

#! /bin/bash

myNR=0

fcAmp(){
sed 's/&/&/g' # sanitize ampersand char (due to yad error message)
}

fcMY(){
while read data; do
echo "$myNR$data"
myNR=$((myNR + 1)) # file counter prefix number
done
}

find /home/roelof/Desktop/FBset/ -name '*.jpg' | \
fcAmp | \
fcMY | \
yad \
--notebook \
--list \
--column "Files" \
--title "Some App Title" \
--fontname "mono 10" \
--width 600 \
--height 300 & \
yad --progress --pulsate --auto-close --auto-kill --button gtk-cancel:1

#---------------------

However, the last line doesn't work properly : i expect the progress bar displays the real progress (of the list-building, while finding files), but it shows "0 %" all the time .. I also wonder how to get such progress bar into the "notebook"; my script gives a second YAD window.

Milos Pavlovic

unread,
Mar 27, 2017, 4:12:08 AM3/27/17
to yad-common
#! /bin/bash

myNR
=0



fcMY
(){
while read data; do


    myNR
=$((myNR + 1))               # file counter prefix number
    echo
"$myNR"
    echo
"$data" | sed 's/&/&/g' # sanitize ampersand char (due to yad error message)
    echo
"#Found $myNR item(s)"      # third line here goes the text for the progress bar


done | tee >(lisT)

   
# A way to kill the progress (well, sort of)
    echo
""
    echo
""
    echo
100 # Printing 100 closes the progress dialog
}

function lisT(){
   
(yad \
   
--notebook \
   
--list --column "Num" \
   
--column "Files" \
   
--column "hidden" \

   
--title "Some App Title" \
   
--fontname "mono 10" \
   
--width 600 \

   
--height 300 \
   
--hide-column="3" \
    --print-column="2" \
    --separator="" >
/home/roelof/Desktop/result.txt # write the result(s) to a file
   
if [[ $? == 1 ]]; then
        rm
-f /home/roelof/Desktop/result.txt
       
exit 0
   
fi) || exit
}

find
/home/roelof/Desktop/FBset/ -name '*.jpg' | \
fcMY
| awk 'NR % 3 == 0;fflush()' | yad --progress --pulsate --auto-close --auto-kill --button gtk-cancel:1 --on-top

# awk - prints every third line and flushes to stdout
#---------------------

Something like that would do. It's a bit ugly (most likely), because I haven't slept much last night...
Reply all
Reply to author
Forward
0 new messages