Bash – How to Make a Progress Dialog for Bash in XFCE

bashwindowxfce

Previously, in KDE, this was simple — I called KDialog with number of steps, I got DCOP handle in return, then I called dcop with that reference and step, and progress dialog got updated.

However, now DCOP is obsolete, and since I moved from KDE 3.5.10 to XFCE, I thought it would be a good idea that instead converting my script from KDialog+DCOP to KDialog+DBUS I migrate to XFCE progress dialog.

So how do you build progress dialog for Bash purposes in XFCE? Bash purpose = I perform some computation in Bash, but the progress is shown in GUI way, as nice dialog on the desktop.

Best Answer

You can use dialog utility. It can works both inside and outside a terminal.

To get it on the X server, you may use its xdialog or gdialog/zenity variant. Take note that zenity is recommendend for XFCE, since its use GTK+. In fact, I think Kdialog is a KDE variant of Xdialog.

Here is a simple Zenity script, running on X server with a yes/no box :

DIALOG=zenity
$DIALOG --title " My first dialog" --clear \
--yesno "Hi, this is my first dialog" 10 30

Here's a simple tutorial with various example about the different dialog available. And there's also a nice tutorial about zenity.

About your graphical progress dialog, there's one dedicated for this purpose. Here's the sample script of the documentation :

#!/bin/sh
(
echo "10" ; sleep 1
echo "# Updating mail logs" ; sleep 1
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 --progress \
  --title="Update System Logs" \
  --text="Scanning mail logs..." \
  --percentage=0

if [ "$?" = -1 ] ; then
        zenity --error \
          --text="Update canceled."
fi