Table of Contents
In this article, we will talk about how to make progress dialog. We will use the --progress option in zenity to do this. You can easily see the software used to download or install have a progress dialog. So have you ever wondered how to create such a progress dialog?
Create a simple progress dialog
Once you have used zenity a few times, it’s easy to find the zenity option that supports creating a progress dialog. Type the following command to create it:
zenity --progress
But as you can see, the dialog is not customized as expected. It’s just a default dialog box and there are no features to allow you to manipulate it.
Zenity reads input data one by one. If the line starts with the # character, it will update the text content by the content of that line. If the line starts with a number, it will update the content by the content of that line. What does this mean? I will explain below.
Progress dialog options
This dialog supports the options presented in the table below.
| Option | Meaning |
--text=text | The text is displayed on the dialog. For example, you can look at the example in the image below. As i said above, zenity will replace the content of line beginning with # for the content of this option. |
--percentage=percentage | Percentage that is set in the dialog. As i said too, zenity will read data from input and replace content of the line begin with a number for the content of this option. |
--auto-close | Automatically close progress dialog when it reaches 100%. |
--pulsate | Specifies that the progress bar pulsates until an EOF character is read from standard input. I rarely use this option, you can try it if you want. |

Script to create a progress dialog
You copy the script below and assign the executable to the script.
Read more: Create a file selection dialog
#!/bin/bash
# Script author: Danie Pham
# Script site: https://devopslite.com
# Script date: 12-01-2018
# Script ver: 1.0
# Script use to create a progress dialog with zenity
# Function create a progress dialog
f_create_dialog () {
# Create a list contain some commands
(
echo "10" ; sleep 1 # This command will echo a line begin with number "10". It will replace --percentage option.
echo "# Updating mail logs" ; sleep 1 # This command will echo a line begin with # character. It will replace --text option.
echo "20" ; sleep 1
echo "# Resetting cron jobs" ; sleep 1
echo "50" ; sleep 1
echo "This line will just be ignored" ; sleep 1
echo "75" ; sleep 1
echo "# Rebooting system" ; sleep 1
echo "100" ; sleep 1
) |
# Zenity reads the data from the commands in the list above
zenity --progress \
--title="Update System Logs" \
--text="Scanning mail logs..." \
--percentage=0
if [ "$?" = -1 ] ; then
zenity --error \
--text="Update canceled."
fi
}
# Function main, use to call funtion f_create_dialog and other
f_main () {
f_create_dialog
}
f_main
exitLet’s try to use scripts to create a dialog and see what the results is.
chmod +x create_progress_dialog
./create_progress_dialog
Conclusion
In the script above, you can replace the echo commands in the list with your other functions or commands. You can adjust it to get your current system information and put the data into zenity to display. A fairly simple but effective command if you can take advantage of it with the bash script.
(This is an article from my old blog that has been inactive for a long time, I don’t want to throw it away so I will keep it and hope it helps someone).