You are not logged in.

#121 2019-11-26 15:41:22

damo
....moderator....
Registered: 2015-08-20
Posts: 6,734

Re: The great yad hacking thread

lpstat and lpadmin may be what you need. For example, get a list of printers with

lpstat -e

Be Excellent to Each Other...
The Bunsenlabs Lithium Desktop » Here
FORUM RULES and posting guidelines «» Help page for forum post formatting
Artwork on DeviantArt  «» BunsenLabs on DeviantArt

Offline

#122 2019-11-27 02:30:28

johnraff
nullglob
From: Nagoya, Japan
Registered: 2015-09-09
Posts: 12,560
Website

Re: The great yad hacking thread

@achim you are aware of the utility system-config-printer?
https://packages.debian.org/stretch/sys … ig-printer
It's not yad, but might already do what you need...


...elevator in the Brain Hotel, broken down but just as well...
( a boring Japan blog (currently paused), now on Bluesky, there's also some GitStuff )

Introduction to the Bunsenlabs Boron Desktop

Offline

#123 2019-11-27 15:18:21

achim
Member
Registered: 2019-08-23
Posts: 40

Re: The great yad hacking thread

@damo
lpstat: Error - unknown option "e".
lpstat -v reads printer information. I do not yet know how to transfer the printer names to variables.

@johnraff
I've already thought of that. However, I would prefer a separate function under yad.

Many greetings
achim

Offline

#124 2019-11-28 03:00:35

damo
....moderator....
Registered: 2015-08-20
Posts: 6,734

Re: The great yad hacking thread

achim wrote:

@damo
lpstat: Error - unknown option "e".
lpstat -v reads printer information. I do not yet know how to transfer the printer names to variables.

Works for me on Buster.

@johnraff
I've already thought of that. However, I would prefer a separate function under yad.

Example idea

### read printer devices
$ lpstat -v
device for Brother: dnssd://Brother%20HL-3140CW%20series._pdl-datastream._tcp.local/
device for Brother_HL_3140CW_series: ipp://BRW2C6FC9166C82.local:631/ipp/print
device for Brother_HL_3140CW_series_jem_laptop: ///dev/null

### put the 3rd fields in an array
$ arrPRINTERS=($(lpstat -v | awk '{print $3}'))

### format result (make a loop if there are more than one)
$ PRINTER_1=${arr[0]%:*} && echo "$PRINTER_1"
Brother

Be Excellent to Each Other...
The Bunsenlabs Lithium Desktop » Here
FORUM RULES and posting guidelines «» Help page for forum post formatting
Artwork on DeviantArt  «» BunsenLabs on DeviantArt

Offline

#125 2019-11-28 12:43:49

achim
Member
Registered: 2019-08-23
Posts: 40

Re: The great yad hacking thread

@misko_2083

Thanks, that's very good. This enables me to build a complete printer dialog.

@damo

The example does not work for me unfortunately. Or I just do not understand it?  sad

Offline

#126 2019-11-28 17:38:23

damo
....moderator....
Registered: 2015-08-20
Posts: 6,734

Re: The great yad hacking thread

achim wrote:

...
@damo

The example does not work for me unfortunately. Or I just do not understand it?  sad

I don't know - you haven't said what you have tried. Post your commands and the output?


Be Excellent to Each Other...
The Bunsenlabs Lithium Desktop » Here
FORUM RULES and posting guidelines «» Help page for forum post formatting
Artwork on DeviantArt  «» BunsenLabs on DeviantArt

Offline

#127 2019-11-29 11:15:01

achim
Member
Registered: 2019-08-23
Posts: 40

Re: The great yad hacking thread

@damo

I just can not manage to formulate a loop that will give me a usable result. For it works now with this command:

lpstat -a | awk '{print $1}'

Nevertheless, many thanks for your support

PS. Maybe you have just told me how to formulate a loop with result from your proposal.

Achim

Offline

#128 2019-11-29 20:33:13

secureIT
New Member
Registered: 2019-11-29
Posts: 1

Re: The great yad hacking thread

Hello Achim,


look at the thread in forums.linuxmint
I think i got a solution ........

Offline

#129 2019-11-29 21:42:30

damo
....moderator....
Registered: 2015-08-20
Posts: 6,734

Re: The great yad hacking thread

achim wrote:

@damo

I just can not manage to formulate a loop that will give me a usable result. For it works now with this command:

lpstat -a | awk '{print $1}'

Nevertheless, many thanks for your support

PS. Maybe you have just told me how to formulate a loop with result from your proposal.

Achim

Quick yad hack to loop through printers, and display your choice

#!/bin/bash
##
## yad-printer.sh

arrP=($(lpstat -a | awk '{print $1}'))

LIST=""

for ((j=0; j<${#arrP[*]}; j++));do
    p="${arrP[$j]}"
    [[ "$p" == "reason" ]] && continue
    LIST="${LIST}FALSE $p "
done

RET=$(yad --list \
    --text="Choose a Printer:" \
    --checklist --width=400 --height=200 \
    --column="Choose" --column="Printer Name" $LIST --separator=":" \
    --button=gtk-ok:0 --button=gtk-cancel:1 \
    )

if (( $? == 1 )); then # cancel button pressed
    exit 0
else
    printer=${RET%*:}
    printer=${printer#*:}
fi

echo -e "\n\tDo what you want with $printer!!\n"

(NB No error checks, and multi-choice is possible, but it was a quick try)


Be Excellent to Each Other...
The Bunsenlabs Lithium Desktop » Here
FORUM RULES and posting guidelines «» Help page for forum post formatting
Artwork on DeviantArt  «» BunsenLabs on DeviantArt

Offline

#130 2019-11-30 01:42:02

achim
Member
Registered: 2019-08-23
Posts: 40

Re: The great yad hacking thread

@damo

A big thank you, now I save a lot of time and do not need any more experiments. An error check I will install.


@secureIT

one reads again and again that the TE wants to close the thread without good reason. That's why I'll do better for myself. I still have many interesting ideas.

achim

Last edited by achim (2019-11-30 01:45:13)

Offline

#131 2019-12-01 21:00:31

achim
Member
Registered: 2019-08-23
Posts: 40

Re: The great yad hacking thread

Hi,

the content of the variable "sprint" is the default printer. Is it possible over this code

RET = $ (yad --list --center --fixed --title = "Printer" --window-icon = "gtk-print" --text = "\ n Currently '$ sprinter' is the default printer \ n \ n The following devices are available: \ n "\
     --radiolist --width = 550 --height = 350 --column = "Check" --column = "printername" $ LIST --separator = ":" \
     --button = gtk-cancel: 1 --button = gtk-ok: 0
     )
dvar = $ (echo $?)

to display the corresponding line as "activated"?

achim

Offline

#132 2019-12-01 21:37:11

damo
....moderator....
Registered: 2015-08-20
Posts: 6,734

Re: The great yad hacking thread

From

man lpstat
...
-p [printer(s)]
            Shows  the  printers  and  whether they are enabled for printing.  If no printers are specified
            then all printers are listed.

This gives output such as

lpstat -p "Brother"
printer Brother is idle.  enabled since Thu 19 Sep 2019 08:32:47 BST

So use a test for the output

if lpstat -p "Brother" | grep -q 'enabled';then echo 'true'; else echo 'false'; fi

You could add something to the name in $LIST eg

for ((j=0; j<${#arrP[*]}; j++));do
    p="${arrP[$j]}"
    [[ "$p" == "reason" ]] && continue
    if lpstat -p "$p" | grep -q 'enabled';then
        p="$p ACTIVE"
    fi
    LIST="${LIST}FALSE $p "
done

NB Untested!


Be Excellent to Each Other...
The Bunsenlabs Lithium Desktop » Here
FORUM RULES and posting guidelines «» Help page for forum post formatting
Artwork on DeviantArt  «» BunsenLabs on DeviantArt

Offline

#133 2019-12-02 15:36:41

achim
Member
Registered: 2019-08-23
Posts: 40

Re: The great yad hacking thread

@damo

I believe that I mispronounced myself in my post # 175. The variable "sprint" already corresponds exactly to the printer "EPSON_WF-3520_Series". When the YAD code is called, this printer is already set as the default. In the YAD window, however, all printers are displayed as "False". EPSON_WF-3520_Series True, but false for all others?
I had a test, because with --column "record number" and --hide-column = 2 two additional columns were inserted. These controlled the display of True and False. Unfortunately, the code did not work.

Achim

Offline

#134 2019-12-02 18:56:43

damo
....moderator....
Registered: 2015-08-20
Posts: 6,734

Re: The great yad hacking thread

Without seeing your code it seems pointless trying to troubleshoot it!


Be Excellent to Each Other...
The Bunsenlabs Lithium Desktop » Here
FORUM RULES and posting guidelines «» Help page for forum post formatting
Artwork on DeviantArt  «» BunsenLabs on DeviantArt

Offline

#135 2019-12-02 19:09:21

achim
Member
Registered: 2019-08-23
Posts: 40

Re: The great yad hacking thread

sorry...

stdr () {
lpstat -d > /tmp/sdr
 sdrucker=$(cat /tmp/sdr)
 sdrucker=${sdrucker%*:}
 sdrucker=${sdrucker#*:}
 echo $sdrucker
 }; export -f stdr

arrP=($(lpstat -a | awk '{print $1}'))

LIST=""

for ((j=0; j<${#arrP[*]}; j++));do
    p="${arrP[$j]}"
    [[ "$p" == "reason" ]] && continue
    LIST="${LIST}FALSE $p "
done

stdr
#if lpstat -p = $(cat /tmp/sdr) | grep -q 'enabled';then echo 'true'; else echo 'false'; fi

RET=$(yad --list --center --fixed --title="Drucker" --window-icon="gtk-print" --text='<span foreground="blue" font="12">Aktuell ist "$sdrucker". Zur Auswahl stehen die folgenden Geräte:</span>' \
    --radiolist --width=550 --height=350 --column "Select" --column="Druckername" $LIST --separator=":" \
    --button=gtk-cancel:1 --button=gtk-ok:0
    )
dvar=$(echo $?)										# Exit-Code auswerten
	
if [[ $dvar == 1 ]] || [[ $dvar == 70 ]] || [[ $dvar == 252 ]]; then	# Taste Abbrechen gedrückt || Skript-Ende mit [X] || Skript-Ende mit [Esc]
exit
else
PRINTER=${RET%*:}
PRINTER=${PRINTER#*:}
fi
exit

Last edited by achim (2019-12-02 19:16:09)

Offline

#136 2019-12-02 19:57:28

damo
....moderator....
Registered: 2015-08-20
Posts: 6,734

Re: The great yad hacking thread

I don't see a variable called "sprint" ??


Be Excellent to Each Other...
The Bunsenlabs Lithium Desktop » Here
FORUM RULES and posting guidelines «» Help page for forum post formatting
Artwork on DeviantArt  «» BunsenLabs on DeviantArt

Offline

#137 2019-12-02 21:00:34

achim
Member
Registered: 2019-08-23
Posts: 40

Re: The great yad hacking thread

Oh, Variable "sprint" = Variable "sdrucker". "sprint" is old.

Last edited by achim (2019-12-03 10:02:51)

Offline

#138 2019-12-04 10:23:12

damo
....moderator....
Registered: 2015-08-20
Posts: 6,734

Re: The great yad hacking thread

My TRUE/FALSE test was failing at first because $sdrucker was saved with a leading whitespace.

I don't see any need to export a function result, and have a tempfile.

#!/bin/bash
##
## yad-printer.sh

arrP=($(lpstat -a | awk '{print $1}'))

sdrucker="$(lpstat -d)"
sdrucker="${sdrucker##* }"   # get string after last whitespace

LIST=""

for ((j=0; j<${#arrP[*]}; j++));do
    p="${arrP[$j]}"
    [[ "$p" == "reason" ]] && continue
    if [[ "$p" == "$sdrucker" ]];then
        LIST="${LIST}TRUE $p "    
    else
        LIST="${LIST}FALSE $p "
    fi
done

RET=$(yad --list --center --fixed --title="Drucker" --window-icon="gtk-print" \
--text='<span foreground="blue" font="12">Aktuell ist "$sdrucker". Zur Auswahl stehen die folgenden Geräte:</span>' \
    --radiolist --width=550 --height=350 --column "Select" --column="Druckername" $LIST --separator=":" \
    --button=gtk-cancel:1 --button=gtk-ok:0
    )
dvar=$(echo $?)										# Exit-Code auswerten
	
if [[ $dvar == 1 ]] || [[ $dvar == 70 ]] || [[ $dvar == 252 ]]; then	# Taste Abbrechen gedrückt || Skript-Ende mit [X] || Skript-Ende mit [Esc]
    exit
else
    PRINTER=${RET%*:}
    PRINTER=${PRINTER#*:}
fi
echo "Chosen PRINTER= $PRINTER"
exit

Be Excellent to Each Other...
The Bunsenlabs Lithium Desktop » Here
FORUM RULES and posting guidelines «» Help page for forum post formatting
Artwork on DeviantArt  «» BunsenLabs on DeviantArt

Offline

#139 2019-12-04 14:02:42

Anton
Member
From: СПб, Россия
Registered: 2019-04-11
Posts: 9

Re: The great yad hacking thread

misko_2083 wrote:

Relax, I'm only messing with you. :-D

I like the way you write the scripts.
They are readable. You have an eye for that.

Я тебя понял.
Спасибо Мишко. wink

Offline

#140 2019-12-04 15:36:02

achim
Member
Registered: 2019-08-23
Posts: 40

Re: The great yad hacking thread

@damo

Fantastic, it works. Sometimes the problem is so close you just can not recognize it. I spent a lot of time searching. Thanks again, I hope I can return the favor smile

achim

Offline

Board footer

Powered by FluxBB