Revision [31746]
This is an old revision of Xdialog examples made by wognath on 2017-11-04 16:16:14.
Xdialog examples
Xdialog is well documented, but examples are hard to find (except within Puppy scripts). Here are a few, which can be copied & pasted into a terminal to try out. Please add useful examples if you have them.How to obtain output from Xdialog
1) exit status $?
yes or ok -> 0, no, cancel, ESC -> 1, timeout or window closed -> 255
with --wizard option, next button -> 0, previous button -> 3
b=$(Xdialog .... 2>&1)
Examples
The series of 2 or 3 numbers after "text" is for sizing. Zeros-> autosize, which may not work well.yesno
Xdialog --timeout 2 --yesno "Choose" 0 0 ; a=$?
sets $a=0, 1 or 255
Xdialog --ok-label Maybe --cancel-label "Maybe not" --yesno "Choose" 0 0 ; a=$?gauge
for i in {0..100..10} ; do echo $i ; sleep 1 ; done | Xdialog --gauge "Ten second countdown" 0 0Progress of a more complex task involving a list of L files. (thanks to gnashley here)
count=0 ; L=$(wc -l </tmp/list)
{ while read file ; do
[do something with $file]
let count++
bc<<<"100*$count/$L"
done < /tmp/list } | Xdialog --gauge "Progress" 0 0inputbox
b=$(Xdialog --inputbox "application to run" 0 0 2>&1)
sets $b=typed text, or /path/file in case of drag & drop
b=$(Xdialog --password=2 --separator "|" --2inputsbox "Open encrypted file" 0 0 file "" password "" 2>&1)
$b=/path/myfile.bfe|p4ssw0rd
radiolist
(single choice from list)b=$(Xdialog --radiolist "Sound" 0 0 0 tag1 "PC" off tag2 "HDMI" on tag3 "BT" off 2>&1)
on/off indicates initial status
sets $b=tag2 for example
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
(2000 is timeout in ms; 0 = no timeout)
update text from std input:while true ; do sleep 1 ; echo -e "XXX\n`date`\nXXX" ; done | Xdialog --infobox "Initial text" 8 60 0
Initial text is 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 or OK
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 2 2 2 for example
Categories
CategoryDevelopmentCategorySoftware