You are not logged in.
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...
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...
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...
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...
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
Be Excellent to Each Other...
FORUM RULES and posting guidelines «» Help page for forum post formatting
Artwork on DeviantArt «» BunsenLabs on DeviantArt
Offline
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.Я тебя понял.
Спасибо Мишко.
Нема на чему Борисе.
Мој Мишко је геније за вожњу.*
https://www.youtube.com/watch?v=krxD25ZNFs4
*Реченица из филма "Ко то тамо пева (1980)"
Offline
hey there!
I found it nice to make a little script which helps me to clean up my download folder as ClusterF suggested:
#!/usr/bin/env bash
# sort the download folder usin rsync
# inspired by ClusterF
# filetypes to sort
arr=( *.doc *.docx *.ebook *.log *.md *.msg *.odt *.org *.pages *.pdf *.rtf *.rst *.tex *.txt *.wpd *.wps )
arr1=( *.aac *.aiff *.ape *.au *.flac *.gsm *.it *.m3u *.m4a *.mid *.mod *.mp3 *.mpa *.pls *.ra *.s3m *.sid *.wav *.wma *.xm *.ogg )
arr2=( *.jpg *.JPG *.jpeg *.png *.xfc *.bmp *.gif )
# change this to use it to sort any folder you like
dls () {
cd $HOME/Downloads
}
# how to process and where to put the various filetypes
docs () {
rsync -bvh --progress --remove-source-files ${arr[@]} $HOME/Documents 2> /dev/null
}
music () {
rsync -bvh --progress --remove-source-files -b ${arr1[@]} $HOME/Music 2> /dev/null
}
iso () {
rsync -bvh --progress --remove-source-files -b *.iso $HOME/Downloads/iso 2> /dev/null
}
mc () {
rsync -bvh --progress --remove-source-files -b *.jar $HOME/.minecraft/mods 2> /dev/null
}
pix () {
rsync -bvh --progress --remove-source-files -b ${arr2[@]} $HOME/Pictures/unsorted/ 2> /dev/null
}
deb () {
rsync -bvh --progress --remove-source-files -b *.deb $HOME/bin 2> /dev/null
}
# insert funky yad dialog for selecting filetypes here
# ..and go
if dls; then
docs
music
iso
mc
pix
deb
fi
exit 1
and as you can see I have room to fill with a yad-dialog to select which file types should be processed, but i cant seem to be figuring out how to create one. I would be able to create a radio-list but multiple choices have to be possible and then i just don't understand how the choice will be passed back to the script to work with.
thanks guys!
naik --greetz
"Kaum macht [Mensch]* es richtig, funktioniert es sofort!"
BL-Kitchen on GitHub
Offline
i just don't understand how the choice will be passed back to the script to work with.
man yad is very comprehensive, but a bit dense. Basically, the return is a pipe-separated string (or you can set a different separator), which you then parse to get the fields. Eg:
DLG=$(yad ...<parameters>...)
echo "${DLG}"
string_1|string_2|string_3|
val_1="$(echo "${DLG}" | awk -F '|' '{print $1}')"
Be Excellent to Each Other...
FORUM RULES and posting guidelines «» Help page for forum post formatting
Artwork on DeviantArt «» BunsenLabs on DeviantArt
Offline
Ive little to no experience with yad, im currently playing around with gxmessage though it doesnt have as much functionality than yad does of course.
@ Naik, the only sort of functionality i could see in using a gui would be to pick the sort source folder.
example would to maybe have a list of common user directories to choose from in a list yad box, then have a sort button and a cancel button.
i can possibly see maybe having a choice of what extensions to process from the arrays, so maybe it could be a button to just process all text files and a button to just process all music files and so on. Way beyond my level of scripting though.
Last edited by clusterF (2019-12-09 11:46:00)
Offline