YAD Checklist - Please can somebody put me out of my misery!

503 views
Skip to first unread message

chris brown

unread,
Nov 5, 2021, 7:03:06 AM11/5/21
to yad-common
Please can somebody put me out of my misery! I'm trying to display the contents of an array created from a dynamic text file in a checklist and as far as I can tell I have tried all the recommended solutions to display the list accurately, but none seemed to work correctly. Some of the information going missing!

My test text file contains the following four lines of information.

sda         disk   7.5G STORE_N_GO
sdb         disk 894.3G NV-C01
mmcblk0     disk  29.7G
nvme0n1     disk 953.9G Sabrent

Having read and researched lots of examples of how to display this information in a checklist, none of them seem to be working.
If I run the code:

#!/bin/bash

IFS=$'\n' myArray=($(cat /home/eviget/eviget_scripts/devinfo3))
devsToMnt=$(for i in $(seq ${#myArray[@]}); do echo "${myArray[$i-1]}"; done | yad --list --center --height="400" --checklist --column="Select" --column="Device to mount:" --print-column="2" --multiple --separator=" ")
exit 0

or this from the terminal I get the same out put with the first and third records missing seethe images below, and If I print the array to the terminal all the records are displayed and I'm at a loss as to know why.  Any help would be much appreciated.


Chris

Screenshot2a.pngScreenshot1.pngScreenshot3.png

robert....@gmail.com

unread,
Nov 7, 2021, 11:29:28 PM11/7/21
to yad-common
Hi, Chris.

If it makes you feel better (or worse), rows 1 and 3 also don't show up for me when "file" is

A
B
C
D

yad --list --checklist --column="Select" --column="Device to mount" --print-column="2" < file

YAD 0.40.0 (GTK+ 3.24.5)

Strange. I'll watch this thread to see if anyone else can figure it out.

Милош Павловић

unread,
Nov 8, 2021, 7:16:09 PM11/8/21
to yad-common
You have two columns col1 and  col2
The first column is checklist which values can be FALSE or TRUE
Select (col1)     Device (col2)
FALSE                A
FALSE                B
FALSE                C
FALSE                D
What it needs is to print FALSE before printing every line from an array.
Here's the relevant part of the script that removes the word "disk"
devsToMnt=$(for i in $(seq ${#myArray[@]})
                do
                  echo FALSE
                  for element in "${myArray[$i-1]}"
                      do
                          read -r col1 TRASH col2 <<< "${element}"
                          echo "${col1} ${col2}"
                  done
            done \
| yad --list \


It can also be split into three columns.
Select (col1)     Device (col2)        Name (col3)
FALSE                A                             N-A
FALSE                B                             N-B
FALSE                C                             N-C
FALSE                D                             N-D

Screenshot_2021-11-09_01-14-25.png

chris brown

unread,
Nov 9, 2021, 11:02:53 AM11/9/21
to yad-common
Thanks for the reply I managed to sort my problem with the following code

file="/home/eviget/eviget_scripts/devinfo3"
disknum=0
lines=()
while IFS= read -r line; do
disknum=$((disknum+1))
lines=("${lines[@]}" "FALSE" "$disknum" "$line")
done <"$file"
diskpicked=$(yad --list --radiolist --title="Disks detected." --text="Select the disk to be copied" --center --width=500 --height=500 --column=In --column=Number --column=Description "${lines[@]}")

Having said that ,  your solution is much better and one I will using moving forward - thanks
Chris

Милош Павловић

unread,
Nov 9, 2021, 12:15:41 PM11/9/21
to yad-common
Here's with five columns, now if device has no label it will write "(no name)", size is a separate column and instead of "100G" writes out "100 GiB"
I think Linux uses Gigibytes instead of Gigabytes, GiB instead od GB.
I changed it in script but didn't update the screenshot.
Screenshot_2021-11-09_17-06-12.png
#!/bin/bash

declare -i disknum
mapfile -d $'\n' -t myArray <"/home/eviget/eviget_scripts/devinfo3"

devsToMnt=$(for i in $(seq ${#myArray[@]})
                do
                  echo FALSE
                  for element in "${myArray[$i-1]}"
                      do
                          read -r col1 TRASH col2 col3 <<< "${element}"
                          disknum+=1
                          echo "${disknum}"
                          echo "${col1}"
                          echo "${col3:=(no name)}"
                          echo "${col2//[a-zA-Z]/ ${col2//[.0-9]/}}iB"
                  done
            done \
| yad --list \
      --center \
      --width="500" \
      --height="400" \
      --text="Select device to mount:" \
      --checklist --column="Select" --column=# --column="Device" --column="Name" --column="Size" \

      --print-column="2" --multiple --separator=" ")

echo $devsToMnt
exit 0
Reply all
Reply to author
Forward
0 new messages