Page 1 of 1

Xdialog: checklist box option

Posted: Fri 10 Apr 2020, 11:33
by nic007
I want to use Xdialog, checklist box option in a script but need some help with the construction thereof. Simple example of what I want:

tag1=1 item1=john status=off
tag2=2 item2=peter status=off
If I select john from the list, the command cp /a.txt /root must be executed.
If I select peter, cp /b.txt /root must be executed.
If I select both from the list, the command for each item must be executed seperately (in other words john and its command, followed by peter and its command).

Thanks

Posted: Fri 10 Apr 2020, 12:11
by MochiMoppel
Try

Code: Select all

ANSWER=$(Xdialog --stdout --checklist "Select one or more" 0 0 6 "1" "John" "off" "2" "Peter" "off")
case /$ANSWER/ in
*/1/*) echo cp a.txt /root ;;&
*/2/*) echo cp b.txt /root ;;
esac

Posted: Fri 10 Apr 2020, 12:22
by nic007
Thanks, I'll give it a try.

Posted: Fri 10 Apr 2020, 13:35
by nic007
Script does not work for me with the & added. Works without the & but only one item's command is executed (even if you select more than one item from the list).

Posted: Fri 10 Apr 2020, 13:38
by MochiMoppel
nic007 wrote:Script does not work for me with the & added
Requires bash 4 or newer.
You didn't specify a particular shell so I assumed that you use bash.

Posted: Fri 10 Apr 2020, 14:32
by nic007
Oh, okay. I was using Racy. Works with the newer Puppys. Thanks.

Posted: Fri 10 Apr 2020, 15:58
by Moose On The Loose
nic007 wrote:Oh, okay. I was using Racy. Works with the newer Puppys. Thanks.
BTW:
I find that if you make the "6" number one more than the number of items, the script looks much better.
If there are So many that the dialog box will be over about 400 pixels tall make the number at least two less than the actual number and also small enough that it comes in under 400. Some people, like me when traveling, are using a machine with a very limited screen.

Posted: Fri 10 Apr 2020, 16:34
by nic007
Moose On The Loose wrote:
nic007 wrote:Oh, okay. I was using Racy. Works with the newer Puppys. Thanks.
BTW:
I find that if you make the "6" number one more than the number of items, the script looks much better.
If there are So many that the dialog box will be over about 400 pixels tall make the number at least two less than the actual number and also small enough that it comes in under 400. Some people, like me when traveling, are using a machine with a very limited screen.
Yes that number is for the space allocated for items in the list. On the average laptop screen about 20 items will fill the screen from top to bottom. But - there should be a scrollbar if you have more items.

Posted: Sat 11 Apr 2020, 15:53
by Moose On The Loose
nic007 wrote:
Moose On The Loose wrote:
nic007 wrote:Oh, okay. I was using Racy. Works with the newer Puppys. Thanks.
BTW:
I find that if you make the "6" number one more than the number of items, the
Yes that number is for the space allocated for items in the list. On the average laptop screen about 20 items will fill the screen from top to bottom. But - there should be a scrollbar if you have more items.
Yes, I knew that. My advice was based on that and the fact that the "average screen" is very like the "average person". There is none that is actually the average. The 400 Pixels size was based on the idea that it is the size of a small screen that may be used. We want our programs to be accessible to all so we should be designing around the most limited case that is reasonable.

The "two less" bit in my advice is because a scrolling window that is just slightly smaller than the list makes a scroll bar that looks a bit wrong. With a bar nearly the full height of the scroll range, if fakes some people out and they seem not to see that it is a scroll bar. I had this happen with something I created for a "non-linux user". I made a bootable CD that did the thing they needed but that one point messed them up.