Revision [31699]
This is an old revision of Xdialog examples made by wognath on 2017-07-12 13:10:14.
Xdialog examples
Xdialog is well documented, but examples are hard to find (except within Puppy scripts).Xdialog documentation
How to obtain output from Xdialog
1) exit status $?
yes or ok -> 0, no or cancel -> 1, timeout -> 255
2) assign stderr to variable for choices in inputbox, radiolist, etc., b=$(Xdialog .... 2>&1)
Examples
yesno
Xdialog --timeout 2 --yesno "Choose" 0 0 ; a=$?
sets $a=0, 1 or 255
gauge
for i in {0..100..10} ; do echo $i ; sleep 1 ; done | Xdialog --gauge "Ten second countdown" 0 0inputbox
b=$(Xdialog --inputbox "application to run" 2>&1)
sets $b=text input
radiolist
(single choice from list)b=$(Xdialog --radiolist "Sound" 12 20 3 tag1 "PC" off tag2 "HDMI" on tag3 "BT" off 2>&1)
on/off indicates initial status
sets $b=tag#
menubox
(single choice from list)b=$(Xdialog --menubox "Choose wifi adapter to connect" 10 42 8 tag1 "card0" tag2 "card1" tag3 "wifi off" 2>&1)
sets $b=tag#
checklist
(any number of selections from list)b=$(Xdialog --checklist "$1" 12 32 12 tag1 "Save" on tag2 "Reboot" off tag3 "Shut down" on 2>&1)
sets $b=tag1/tag3 for example if 1 and 3 are checked
infobox
Xdialog --infobox "important message" 0 0 2000
(timeout 2000 ms)
update text from std input:while true ; do echo -e "XXX\n`date`\nXXX" ; sleep 1 ; done | Xdialog --infobox "Initial text" 8 60 0
Initial text is immediately overwritten. XXX = new text tag.
timeout and interval
--interval # is the interval at which choices are registered, in ms. If absent, no choice is registered ($b="") unless OK is clicked.If an interval equal to the timeout is used, the latest choice is returned, even if OK is not clicked before timeout.
b=(Xdialog --timeout 4 --interval 4000 --radiolist "asldkjf" 12 20 3 1 "first choice" off 2 "second choice" on 3 "third choice" off 2>&1)
sets $b=latest choice on timeout
If a shorter interval is used, a space-delimited history of choices is returned.b=$(Xdialog --timeout 4 --interval 200 --menubox "text" 10 42 8 1 "first choice" 2 "second choice" 3 "third choice" 2>&1)
might return $b=1 1 1 2 2 3 2 1 2 2 2 2 1 for example
Categories
CategoryDevelopmentCategorySoftware