Xdialog make a ratiolist from a Directory listing?
- HoerMirAuf
- Posts: 255
- Joined: Tue 22 Jan 2008, 12:11
- Location: Würzburg
Xdialog make a ratiolist from a Directory listing?
Hi Volks.
I am a novice in scripting bash scripts and/or Xdialog or gtkdialog
I want to make a ratiolist, where i can choose on of all folders in a directory. I am interested in to do this in Xdialog also in gtkdialog
i know a little bit about "ls -d */" and about to build the ratiolist. But how can i make now a ratiolist from the result from "ls -d */" ??
Maybe anyone can explaine me or give me a hint or an example?
I am a novice in scripting bash scripts and/or Xdialog or gtkdialog
I want to make a ratiolist, where i can choose on of all folders in a directory. I am interested in to do this in Xdialog also in gtkdialog
i know a little bit about "ls -d */" and about to build the ratiolist. But how can i make now a ratiolist from the result from "ls -d */" ??
Maybe anyone can explaine me or give me a hint or an example?
Here is an example from don570's bulldog finder (I think).
It gives a small gtkdialog gui of all mounted drives.
Maybe a good starting point ?
Remove the fake '.gz' and make executable.
It gives a small gtkdialog gui of all mounted drives.
Maybe a good starting point ?
Remove the fake '.gz' and make executable.
- Attachments
-
- drive-list.sh.gz
- (1.88 KiB) Downloaded 207 times
[b][url=http://lazy-puppy.weebly.com]LazY Puppy[/url][/b]
[b][url=http://rshs-dna.weebly.com]RSH's DNA[/url][/b]
[url=http://murga-linux.com/puppy/viewtopic.php?t=91422][b]SARA B.[/b][/url]
[b][url=http://rshs-dna.weebly.com]RSH's DNA[/url][/b]
[url=http://murga-linux.com/puppy/viewtopic.php?t=91422][b]SARA B.[/b][/url]
-
- Posts: 282
- Joined: Wed 16 Dec 2009, 21:38
- Location: Earth
Re: Xdialog make a ratiolist from a Directory listing?
Code: Select all
#!/bin/sh
for ONEFILE in /path/*; do
[ -d ${ONEFILE} ] || continue
DIALOGLIST="${DIALOGLIST} ${ONEFILE} - off"
done
Xdialog --checklist "Directories" 0 0 5 ${DIALOGLIST}
SUUM CUIQUE.
- MochiMoppel
- Posts: 2084
- Joined: Wed 26 Jan 2011, 09:06
- Location: Japan
Here a slight variation of PANZERKOPF's code:
Haven't figured out yet how to accomodate code for directory names containing spaces.
Code: Select all
#!/bin/sh
DIRECTORY="/root"
for ONEFILE in "$DIRECTORY"/*; do
[ -d $ONEFILE ] || continue
DIALOGLIST="${DIALOGLIST} ${ONEFILE} ${ONEFILE##*/} off"
done
ANSWER=`Xdialog --no-tags --stdout --radiolist "Subdirectories in $DIRECTORY" 30 30 5 ${DIALOGLIST}`
Xdialog --msgbox "$ANSWER" 5 30
- technosaurus
- Posts: 4853
- Joined: Mon 19 May 2008, 01:24
- Location: Blue Springs, MO
- Contact:
Why not just use:
Code: Select all
Xdialog --dselect $PARENTDIR 0 0
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].
- MochiMoppel
- Posts: 2084
- Joined: Wed 26 Jan 2011, 09:06
- Location: Japan
- technosaurus
- Posts: 4853
- Joined: Mon 19 May 2008, 01:24
- Location: Blue Springs, MO
- Contact:
The result is the same, radio buttons only allow one selection... the same as dselect... except that the intention is more clear with dselect
A radiolist can be done:...but I don't find it as appealing as a simple -dselect
A radiolist can be done:
Code: Select all
A='Xdialog --no-tags --radiolist "select something" 0 0 9 '
for x in *;do
[ -d "$x" ] && A="$A \"$x\" \"$x\" 0 "
done
RESULT=`eval $A`
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].
-
- Posts: 282
- Joined: Wed 16 Dec 2009, 21:38
- Location: Earth
I presumed HoerMirAuf wants to choose not only one but number of directories at same time, therefore I recommended a checklist instead of radiolist.technosaurus wrote:Why not just use:Code: Select all
Xdialog --dselect $PARENTDIR 0 0
SUUM CUIQUE.
- technosaurus
- Posts: 4853
- Joined: Mon 19 May 2008, 01:24
- Location: Blue Springs, MO
- Contact:
... I have no idea what a "ratiolist" is either or "on" of all folders ... but I assumed "radiolist" and "one".... honestly Zigbert's pprocess2 is a better looking example for gtkdialog selections than the Xdialog --radiolistPANZERKOPF wrote:I presumed HoerMirAuf wants to choose not only one but number of directories at same time, therefore I recommended a checklist instead of radiolist.
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].
- MochiMoppel
- Posts: 2084
- Joined: Wed 26 Jan 2011, 09:06
- Location: Japan
Re: Xdialog make a ratiolist from a Directory listing?
And now the ultimate challenge :
Usefulness apart, at least it could serve as a blueprint for reading any external list into a radiolist :HoerMirAuf wrote: But how can i make now a ratiolist from the result from "ls -d */" ??
Code: Select all
ls -d */ > /tmp/list
A='Xdialog --no-tags --stdout --radiolist "select something" 0 0 9 '
while read x; do
A="$A "$x" "$x" 0 "
done < /tmp/list
RESULT=`eval $A`
- technosaurus
- Posts: 4853
- Joined: Mon 19 May 2008, 01:24
- Location: Blue Springs, MO
- Contact:
Re: Xdialog make a ratiolist from a Directory listing?
That does the same thing as my example except that it requires an extra external binary, and superfluous file write and readMochiMoppel wrote:And now the ultimate challenge :Usefulness apart, at least it could serve as a blueprint for reading any external list into a radiolist :HoerMirAuf wrote: But how can i make now a ratiolist from the result from "ls -d */" ??Code: Select all
ls -d */ > /tmp/list A='Xdialog --no-tags --stdout --radiolist "select something" 0 0 9 ' while read x; do A="$A "$x" "$x" 0 " done < /tmp/list RESULT=`eval $A`
ls -d */ is roughly the same as echo */ but echo is a shell builtin (much faster)
rather than writing to a file as command >file (slow) you can do VAR=`command` and then you can echo $VAR | through a pipe or use <<< $VAR redirection
BTW, my example needed --stdout (Xdialog has some stupid defaults) ... and the [ -d ... ] bit could be replace with a */
Code: Select all
A='Xdialog --stdout --no-tags --radiolist "select something" 0 0 9 '
for x in */;do A="$A "$x" "$x" 0 ";done
RESULT=`eval $A`
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].
- L18L
- Posts: 3479
- Joined: Sat 19 Jun 2010, 18:56
- Location: www.eussenheim.de/
Off-Topic of the topic
The assumption radiolist is right.technosaurus wrote:... I have no idea what a "ratiolist" is
In Franconian dialect (HoerMirAuf's Location Würzburg is the capital of Lower Franconia) the pronounciation of d and t are swapped, same for b and p when Franconians want to speak "Hochdeutsch". This phenomen has been stuff for some sketches. e.g.:
http://www.youtube.com/watch?v=VdkwkASm6OM
Watch and listen Willy Astor - Wortspiele Franken - Frankenlied - Live! +Text 4:09 -4:12
Have fun
-
- Posts: 282
- Joined: Wed 16 Dec 2009, 21:38
- Location: Earth
Re: Off-Topic of the topic
Thanks for correction.L18L wrote: The assumption radiolist is right.
If he wants to choose only one directory, an example shown by technosaurus (--dselect) is simpler and better for this purpose.
SUUM CUIQUE.
- HoerMirAuf
- Posts: 255
- Joined: Tue 22 Jan 2008, 12:11
- Location: Würzburg
Damn guys!
Thank you so much for your many replies. I have to check them all out.
Maybe a little mor explain to my request:
I want only choose one Directory from a lot.
It is not neccesary to solve this with "ls -d */" ... this was the only idea, i have had.
But i cant take a "Xdialog -deselct" box, because there are subfolders in the Directory i want to choose ... and with deselect this subfolders are also selectable ... ore not?
Ok ... now i will try out your suggestions
Thanks a lot !
Thank you so much for your many replies. I have to check them all out.
Maybe a little mor explain to my request:
I want only choose one Directory from a lot.
It is not neccesary to solve this with "ls -d */" ... this was the only idea, i have had.
But i cant take a "Xdialog -deselct" box, because there are subfolders in the Directory i want to choose ... and with deselect this subfolders are also selectable ... ore not?
Ok ... now i will try out your suggestions
Thanks a lot !
-
- Posts: 282
- Joined: Wed 16 Dec 2009, 21:38
- Location: Earth
- HoerMirAuf
- Posts: 255
- Joined: Tue 22 Jan 2008, 12:11
- Location: Würzburg
hmmmm
this is just a very nice solution... Thank you all a lot!
But eval will give back the result only in a terminal output. Why eval dont write it to the variable "RESULT" ??
Code: Select all
A='Xdialog --no-tags --radiolist "select something" 0 0 5 '
for x in *;do
[ -d "$x" ] && A="$A \"$x\" \"$x\" 0 "
done
RESULT=`eval $A`
But eval will give back the result only in a terminal output. Why eval dont write it to the variable "RESULT" ??
-
- Posts: 282
- Joined: Wed 16 Dec 2009, 21:38
- Location: Earth
IMHO Xdialog prints a result to stderr by default. It needs additional option "--stdout"HoerMirAuf wrote:hmmmm
But eval will give back the result only in a terminal output. Why eval dont write it to the variable "RESULT" ??
for printing to stdout.
Change first line of code:
Code: Select all
A='Xdialog --stdout --no-tags --radiolist "select something" 0 0 5 '
SUUM CUIQUE.
- HoerMirAuf
- Posts: 255
- Joined: Tue 22 Jan 2008, 12:11
- Location: Würzburg
- Moose On The Loose
- Posts: 965
- Joined: Thu 24 Feb 2011, 14:54
You can also use the 2>&1 construct to re-rout the stderr to stdoutPANZERKOPF wrote:IMHO Xdialog prints a result to stderr by default. It needs additional option "--stdout"HoerMirAuf wrote:hmmmm
But eval will give back the result only in a terminal output. Why eval dont write it to the variable "RESULT" ??
for printing to stdout.
Change first line of code:Code: Select all
A='Xdialog --stdout --no-tags --radiolist "select something" 0 0 5 '
A while back, on puppy 4.3.1, I wrote a thing that needed to ask a lot of questions via Xdialog. I discovered to my horror that after so many calls to Xdialog in a script, it would start to fail. As a result, I ended up recoding it to use just "dialog" and pop up a terminal. Hopefully this problem won't plague people today.