LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-12-2021, 09:04 AM   #1
cefer
LQ Newbie
 
Registered: Aug 2021
Posts: 2

Rep: Reputation: Disabled
Help with yad


Hi
I am new with yad and i need help
I have this script:

#!/bin/bash
cmd=(
yad
--button="Office":libreoffice
--button="Text editor":geany
--button="Printer":'firefox "localhost:631"'
--button="File manager" : pcmanfm
--button="Terminal":xterm
--button="Videos":smplayer
)
"${cmd[@]}"

1) The line "Printer" not work. I think could be the colon, but i dont know how to make this work as expected

2) Buttons are show in horizontal line one to right to the previous. I wish to display one under another. It is possible?

Thanks in advance
 
Old 08-12-2021, 12:38 PM   #2
kilgoretrout
Senior Member
 
Registered: Oct 2003
Posts: 2,862

Rep: Reputation: 343Reputation: 343Reputation: 343Reputation: 343
I've run into similar problems with yad, namely you have a yad button calling an executable with an argument like:
Code:
yad --button=Test:dolphin /etc
and in the above dolphin will open to the users home directory ignoring the argument to open dolphin at /etc. I think that's the same problem you're having and trying to solve with a creative use of quotes. I've never been able to find such a solution that will work but I haven't looked really hard. The workaround I use is to simply create a separate bash script and call that from the button. In your case, create a bash script called, eg do-print:
Code:
#!bin/bash
firefox localhost:631
Your script then becomes:
Code:
#!/bin/bash
cmd=(
yad
--button="Office":libreoffice
--button="Text editor":geany
--button="Printer":./do-print
--button="File manager" : pcmanfm
--button="Terminal":xterm
--button="Videos":smplayer
)
"${cmd[@]}"
This assumes your little do-print script is in the same directory as your main yad script.
 
Old 08-12-2021, 12:41 PM   #3
shruggy
Senior Member
 
Registered: Mar 2020
Posts: 2,550

Rep: Reputation: Disabled
Quote:
Originally Posted by cefer View Post
The line "Printer" not work. I think could be the colon
No, it's not about the colon. You cannot specify arguments to the command like this. In your example, yad takes firefox "localhost:631" as the command verb. There is no such command: the command is firefox.

You'll have to supply return codes instead of commands, then evaluate them (e.g. in a case statement).
 
Old 08-12-2021, 09:58 PM   #4
kilgoretrout
Senior Member
 
Registered: Oct 2003
Posts: 2,862

Rep: Reputation: 343Reputation: 343Reputation: 343Reputation: 343
Quote:
You'll have to supply return codes instead of commands, then evaluate them (e.g. in a case statement).
I didn't explain myself very clearly. What I gave him will work; I've run it myself successfully. Here's the problem as I see it.
The simplest syntax for a yad button to trigger the running of an executable, say firefox, is:
Code:
$ yad --button="Firefox":firefox
This will give you a yad box with one button entitled "Firefox" which, when pressed launches firefox. The original poster wanted to access the cups configuration page by opening firefox at localhost:631. If you run the following in a terminal:
Code:
$ firefox localhost:631
firefox launches and opens at the cups configuration page. However, if you create a yad box to do the same with:
Code:
$ yad --button="Printer":firefox localhost:631
This will give you a yad box with a single button entitled "Printer" which, when pressed launches firefox which opens at the configured home page instead of the desired cups configuration page at localhost:631. In short, the argument following firefox is ignored and firefox opens as usual at its home page. I believe all the fooling around with quotes by the OP on the relevant line was an attempt to force firefox to open at localhost:631 instead of the home page. I doesn't work and I've never gotten it to work with yad buttons on similar problems in the past. Making a separate bash script to call the executable with the desired argument was my workaround.
 
Old 08-13-2021, 06:02 AM   #5
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,205
Blog Entries: 1

Rep: Reputation: 1565Reputation: 1565Reputation: 1565Reputation: 1565Reputation: 1565Reputation: 1565Reputation: 1565Reputation: 1565Reputation: 1565Reputation: 1565Reputation: 1565
I don't have such yad, but I'd try something like this:
Code:
#!/bin/bash
cmd=$(
yad
--button="Office:libreoffice"
--button="Text editor:geany"
--button="Printer:firefox localhost:631"
--button="File manager:pcmanfm"
--button="Terminal:xterm"
--button="Videos:smplayer"
)
# check for $?
eval "$cmd"
 
Old 08-13-2021, 07:00 AM   #6
shruggy
Senior Member
 
Registered: Mar 2020
Posts: 2,550

Rep: Reputation: Disabled
^That won't work. yad --button considers everything after the colon to be a command verb, i.e. it will try to execute
Code:
sh -c 'firefox\ localhost:631'
with the result
Code:
sh: firefox localhost:631: command not found
What I suggested in #3 is
Code:
#!/bin/sh
yad \
  --button='Office':11 \
  --button='Text editor':22 \
  --button='Printer':33 \
  --button='File manager':44 \
  --button='Terminal':55 \
  --button='Videos':66
case $? in
  11) libreoffice;;
  22) geany;;
  33) firefox localhost:631;;
  44) pcmanfm;;
  55) xterm;;
  66) smplayer;;
esac

Last edited by shruggy; 08-13-2021 at 09:58 AM.
 
1 members found this post helpful.
Old 08-13-2021, 07:05 AM   #7
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,205
Blog Entries: 1

Rep: Reputation: 1565Reputation: 1565Reputation: 1565Reputation: 1565Reputation: 1565Reputation: 1565Reputation: 1565Reputation: 1565Reputation: 1565Reputation: 1565Reputation: 1565
Does `yad` actually execute the command? I cannot test it right now, but the manual suggests it just prints it to stdout.
 
Old 08-13-2021, 07:11 AM   #8
shruggy
Senior Member
 
Registered: Mar 2020
Posts: 2,550

Rep: Reputation: Disabled
No, yad actually executes it. Unless you're creating a full-blown form with yad where you can do all sorts of things. E.g., this should work
Code:
echo firefox localhost:631|yad --form --field=Printer:FBTN

Last edited by shruggy; 08-13-2021 at 10:11 AM.
 
1 members found this post helpful.
Old 08-16-2021, 01:58 PM   #9
cefer
LQ Newbie
 
Registered: Aug 2021
Posts: 2

Original Poster
Rep: Reputation: Disabled
I do not wish to print

Sorry if there was a bad explanation. The intention is not to print. It is to open the configuration of CUPS in port 631
And nobody has answered point 2
 
Old 08-16-2021, 04:34 PM   #10
boughtonp
Senior Member
 
Registered: Feb 2007
Location: UK
Distribution: Debian
Posts: 1,618

Rep: Reputation: 1315Reputation: 1315Reputation: 1315Reputation: 1315Reputation: 1315Reputation: 1315Reputation: 1315Reputation: 1315Reputation: 1315Reputation: 1315
Quote:
Originally Posted by cefer View Post
2) Buttons are show in horizontal line one to right to the previous. I wish to display one under another. It is possible?
I don't think the dialog buttons (created with --button) can be stacked vertically - you need to create them as form field buttons to do that:

Code:
yad \
 --form \
 --field="Office":fbtn "echo Office pressed" \
 --field="Text editor":fbtn "echo Text editor pressed" \
 --field="Videos":fbtn "echo Videos pressed" \
 --no-buttons

Last edited by boughtonp; 08-16-2021 at 04:38 PM.
 
Old 08-17-2021, 01:36 AM   #11
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 17,783
Blog Entries: 11

Rep: Reputation: 5383Reputation: 5383Reputation: 5383Reputation: 5383Reputation: 5383Reputation: 5383Reputation: 5383Reputation: 5383Reputation: 5383Reputation: 5383Reputation: 5383
Quote:
Originally Posted by cefer View Post
Sorry if there was a bad explanation. The intention is not to print. It is to open the configuration of CUPS in port 631
That was answered in 3 different ways. Please read the whole thread.

Quote:
Originally Posted by cefer View Post
And nobody has answered point 2
Except yad documentation.
 
Old 08-17-2021, 12:34 PM   #12
kilgoretrout
Senior Member
 
Registered: Oct 2003
Posts: 2,862

Rep: Reputation: 343Reputation: 343Reputation: 343Reputation: 343
Code:
#!/bin/bash
cmd=(
yad --form --width=250  \
--field="Office":fbtn "libreoffice" \
--field="Text editor":fbtn "geany" \
--field="Printer":fbtn "firefox localhost:631" \
--field="File manager":fbtn "pcmanfm" \
--field="Terminal":fbtn "xterm" \
--field="Videos":fbtn "smplayer" \
--button=gtk-cancel:1
)
"${cmd[@]}"
That should do it.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Please help me with a YAD Button problem! GladCat Linux - Newbie 3 03-30-2021 12:59 PM
[SOLVED] YAD (ex zenity) front-end for mcrypt and mdecrypt Michael Uplawski Linux - General 5 02-12-2016 06:43 AM
Want to install yad. Can't seem to even add the repository honest_abe Linux - Software 8 05-03-2015 10:57 AM
LXer: Multiple-item data entry with YAD LXer Syndicated Linux News 0 04-07-2014 11:51 AM
[SOLVED] How to debug undefined reference to library function (yad 0.5.1)? catkin Linux - Software 3 10-17-2010 07:08 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:35 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration