Wiki source for Xdialog examples


Show raw source

[[HomePage]] > [[SoftwareIndex Software Index]] > [[SoftwareDevelopment Development]] > [[Xdialog]]

======Xdialog examples======
[[http://web.mit.edu/outland/share/doc/Xdialog-2.1.2/index.html 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
2) assign stderr to variable for choices in inputbox, radiolist, etc.,
{{color text='b=$(Xdialog .... 2>&1)' c='green'}}
or {{color text='b=$(Xdialog --stdout .... )' c='green'}}

====Examples====
The series of 2 or 3 numbers after "text" is for sizing. Zeros-> autosize, which may not work well.

==yesno==
**{{color text='Xdialog --timeout 2 --yesno "Choose" 0 0 ; a=$?' c='green'}}**
sets $a=0, 1 or 255
**{{color text='Xdialog --ok-label Maybe --cancel-label "Maybe not" --yesno "Choose" 0 0 ; a=$?' c='green'}}**

==gauge==
**{{color text='for i in {0..100..10} ; do echo $i ; sleep 1 ; done | Xdialog --gauge "Ten second countdown" 0 0' c='green'}}**
Progress of a more complex task involving a list of L files. (thanks to gnashley [[https://www.linuxquestions.org/questions/programming-9/need-help-with-dialog-xdialog-gauge-option-271705/ here]])
**{{color text='count=0 ; L=$(wc -l </tmp/list)'c='green'}}**
**{{color text='{ while read file ; do'c='green'}}**
**{{color text='[do something with $file]'c='green'}}**
**{{color text='let count++ 'c='green'}}**
**{{color text='bc<<<"100*$count/$L"'c='green'}}**
**{{color text='done < /tmp/list } | Xdialog --gauge "Progress" 0 0'c='green'}}**

==inputbox==
**{{color text='b=$(Xdialog --inputbox "application to run" 0 0 2>&1)' c='green'}}**
sets $b=typed text, or /path/file in case of drag & drop
**{{color text='b=$(Xdialog --password=2 --separator "|" --2inputsbox "Open encrypted file" 0 0 file "" password "" 2>&1)' c='green'}}**
$b=/path/myfile.bfe|p4ssw0rd

==radiolist==
(single choice from list)
**{{color text='b=$(Xdialog --radiolist "Sound" 0 0 0 ' c='green'}}tag1 "PC" off tag2 "HDMI" on tag3 "BT" off{{color text=' 2>&1)' c='green'}}**
on/off indicates initial status
sets $b=tag2 for example

==menubox==
(single choice from list)
**{{color text='b=$(Xdialog --menubox "Choose wifi adapter to connect" 10 42 8 ' c='green'}}tag1 "card0" tag2 "card1" tag3 "wifi off" {{color text=' 2>&1)' c='green'}}**
sets $b=tag#

==checklist==
(any number of selections from list)
**{{color text='b=$(Xdialog --checklist "$1" 12 32 12 ' c='green'}} tag1 "Save" on tag2 "Reboot" off tag3 "Shut down" on {{color text=' 2>&1)' c='green'}}**
sets $b=tag1/tag3 for example if 1 and 3 are checked

==infobox==
**{{color text='Xdialog --infobox "important message" 0 0 2000' c='green'}}**
(2000 is timeout in ms; 0 = no timeout)
update text from std input:
**{{color text='while true ; do sleep 1 ; echo -e "XXX\n`date`\nXXX" ; done | Xdialog --infobox "Initial text" 8 60 0' c='green'}}**
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.
**{{color text='b=$(Xdialog --timeout 4 --interval 4000 --radiolist "asldkjf" 12 20 3 ' c='green'}}1 "first choice" off 2 "second choice" on 3 "third choice" off{{color text=' 2>&1)' c='green'}}**
sets $b=latest choice on timeout or OK
If a shorter interval is used, a space-delimited history of choices is returned.
**{{color text='b=$(Xdialog --timeout 4 --interval 200 --menubox "text" 10 42 8' c='green'}} 1 "first choice" 2 "second choice" 3 "third choice"{{color text=' 2>&1)' c='green'}} **
might return $b=1 1 1 2 2 2 2 2 for example


----
==Categories==
CategoryDevelopment
CategorySoftware

Valid XHTML :: Valid CSS: :: Powered by WikkaWiki