Shell script – Zenity list dialog tutorial

On this Shell script tutorial, I am going to learn how to show a list dialog using Zenity. Zenity list dialog provide an interesting way to show a list box/list dialog using Shell script. See the example below:

Create a new file

[codesyntax lang=”bash”]

nano test.sh

[/codesyntax]

Insert the following lines

[codesyntax lang=”bash”]

cd /home/dhani/Downloads
answer=$(ls *.deb | zenity --list --title "Zenity tutorial" --column "List of files")
case $? in
0) 
if ["$answer" == ""]; then
zenity --warning --text "You choose nothing"
else
zenity --info --text "you choose $answer"
fi;;
1)
;;
*)
zenity --warning --text "No file selected";;
esac

[/codesyntax]

Then save it and make it executable then, run it.

[codesyntax lang=”bash”]

chmod +x test.sh
sh test.sh

[/codesyntax]

The code above will list any files with DEB extension under /home/dhani/Downloads directory.

zenity list dialog 1

When you click a DEB file from the list and press OK, it will display an info dialog.

zenity list dialog 2

When OK button pressed without selecting any file, it will show

zenity list dialog 3

Thank you see you on the next Shell Script tutorial.

Admin

2 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *