Search code examples
bashubuntuzenity

How to use Zenity to display a files contents with tickboxes beside each line of the file


Im trying to give a visual output for a file listing i have. What i want to be able to do is display a tick box beside each line from the file

I have thrown together the following zenity command but my main problem is my file listings can be quite long. From the command below i define the values by TRUE "" or FALSE ""

My question is can i read the contents and place them in the following command (or something similar) without having to make a massively long command

ans=$(zenity  --list  --text "Show List" --checklist  --column "Pick" --column "List" FALSE "BLAH" TRUE "Blah" FALSE "Blah2" FALSE "Blah3" --separator=":"); echo $ans

Regards

Paul


Solution

  • # create an array with FALSE and lines from the file
    unset list
    while read -r line
    do
        list+=("FALSE")
        list+=("$line")
    done < data_file
    
    # set some entries to TRUE
    for entry in 0 2 5 11 12 19
    do
        list[entry]="TRUE"
    done
    
    # display the dialog
    ans=$(zenity --list --text "Show List" --checklist --column "Pick" --column "List" "${list[@]}" --separator=":")
    echo $ans