You are not logged in.

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

damo
....moderator....
Registered: 2015-08-20
Posts: 5,271

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...

FORUM RULES and posting guidelines «» Help page for forum post formatting
Artwork on DeviantArt  «» BunsenLabs on DeviantArt

Offline

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

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

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

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

damo
....moderator....
Registered: 2015-08-20
Posts: 5,271

Re: The great yad hacking thread

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

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

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

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

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

damo
....moderator....
Registered: 2015-08-20
Posts: 5,271

Re: The great yad hacking thread

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

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

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

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

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

damo
....moderator....
Registered: 2015-08-20
Posts: 5,271

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...

FORUM RULES and posting guidelines «» Help page for forum post formatting
Artwork on DeviantArt  «» BunsenLabs on DeviantArt

Offline

#183 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

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

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

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

#185 2019-12-04 20:00:26

damo
....moderator....
Registered: 2015-08-20
Posts: 5,271

Re: The great yad hacking thread

smile


Be Excellent to Each Other...

FORUM RULES and posting guidelines «» Help page for forum post formatting
Artwork on DeviantArt  «» BunsenLabs on DeviantArt

Offline

#186 2019-12-05 10:52:10

misko_2083
Member
Registered: 2016-05-24
Posts: 252

Re: The great yad hacking thread

Anton wrote:
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

Нема на чему Борисе.
Мој Мишко је геније за вожњу.* wink
https://www.youtube.com/watch?v=krxD25ZNFs4
*Реченица из филма "Ко то тамо пева (1980)"

Offline

#187 2019-12-09 08:44:15

Naik
Member
From: Lipsia
Registered: 2015-10-03
Posts: 186

Re: The great yad hacking thread

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

#188 2019-12-09 09:52:52

damo
....moderator....
Registered: 2015-08-20
Posts: 5,271

Re: The great yad hacking thread

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

#189 2019-12-09 11:42:22

clusterF
Member
Registered: 2019-05-07
Posts: 315

Re: The great yad hacking thread

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)


"Common sense is like deodorant, those who need it the most never use it."

git: clusterF

Offline

Board footer

Powered by FluxBB