You are not logged in.
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
@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 )
Offline
@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
@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
@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?
Offline
...
@damoThe example does not work for me unfortunately. Or I just do not understand it?
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
@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
Hello Achim,
look at the thread in forums.linuxmint
I think i got a solution ........
Offline
@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
@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
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
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
@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
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
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
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
Oh, Variable "sprint" = Variable "sdrucker". "sprint" is old.
Last edited by achim (2019-12-03 10:02:51)
Offline
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
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.
Я тебя понял.
Спасибо Мишко.
Offline
@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
achim
Offline