You are not logged in.

#376 2020-03-17 00:16:18

qinohe
Member
From: Netherlands
Registered: 2012-06-20
Posts: 1,494

Re: Dmenu Hacking Thread

Yes, that makes sense and behaves when embedded art isn't found;)

Path don't need to be expanded if '-maxdepth' is used.
You can even add a second(should be first then) bemenu to choose from F.I. a genre(if your music is well ordered!) by using 'maxdepth' and trowing it in an array, just a thought.
Even using one(genre) and playing it directly would be a possibility, which would be my choice for I only own music I like to play, entering(click play) the random choice seems a bit far fetched... hmm

Offline

#377 2020-03-17 00:35:52

cirrus
Member
From: Glasgow Scotland
Registered: 2012-08-24
Posts: 340
Website

Re: Dmenu Hacking Thread

Qinoe. Again thanks for sharing the knowledge, I've picked up a few great tips from yourself & trilby, (especially no longer harming felines) as for the random | shuf thing, I use this merely to show random/different order of mp3's in the *menu -l dropdown.

Last edited by cirrus (2020-03-17 00:39:38)

Offline

#378 2020-05-12 16:16:53

kristoferus
Member
Registered: 2015-09-08
Posts: 27

Re: Dmenu Hacking Thread

Hi !

I use this script to see and switch to a opened window

#!/bin/bash
  
#!/bin/bash
num=$(wmctrl -l | sed 's/  / /' | cut -d " " -f 4- | nl -w 3 -n rn | sed -r 's/^([ 0-9]+)[ \t]*(.*)$/\1 - \2/' | dmenu -l 20 | cut -d '-' -f -1)
[[ -z "$num" ]] && exit
wmctrl -l | sed -n "$num p" | cut -c -10 | xargs wmctrl -i -a

How do i need to adapt this script to see also the name of the app but without the first to fields for example:

wmctrl -lx

0x01400003  3 pcmanfm.Pcmanfm       HOME to_dokument

to this:

pcmanfm.Pcmanfm       HOME to_dokument

or

Pcmanfm       HOME to_dokument

Thanks !

kind regrads

kirstoferus

Last edited by kristoferus (2020-05-12 17:06:18)

Offline

#379 2020-05-12 17:02:25

qinohe
Member
From: Netherlands
Registered: 2012-06-20
Posts: 1,494

Re: Dmenu Hacking Thread

Please use [ code ] tags (see)  https://bbs.archlinux.org/help.php#bbcode

Something like?

wmctrl -lx|awk '{print $3, $4, $5}'

Offline

#380 2020-05-12 17:08:27

kristoferus
Member
Registered: 2015-09-08
Posts: 27

Re: Dmenu Hacking Thread

Hi !

I have adapt my post with code tags :

YES !

kind regards

Last edited by kristoferus (2020-05-12 17:08:52)

Offline

#381 2020-05-12 17:39:23

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,517
Website

Re: Dmenu Hacking Thread

That first line is ... a bit much.  There is never any reason to pipe through that many text processing tools that can all do basically the same thing.  I don't use wmctrl to test, but this should produce the same result:

num=$(wmctrl -l | awk '{ $1=$2=$3=""; gsub(/^ */,""); printf "%3d - %s\n", NR, $0; }' | dmenu -l 20 | cut -d' ' -f 1)

It'd be even easier if wmctrl allowed you to specify output format.  I don't see any such option from a quick glance at the man page, but it wouldn't surprise me if it existed.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#382 2020-05-12 17:50:01

qinohe
Member
From: Netherlands
Registered: 2012-06-20
Posts: 1,494

Re: Dmenu Hacking Thread

smile @Trilby, I thought I give a hint.. you provide the answer right away... and a nice one!

Offline

#383 2020-05-12 18:10:51

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,517
Website

Re: Dmenu Hacking Thread

Oh, no, I was addressing the first line in the script which had pipe cancer.  Your addressed the direct question well on how to write the last line.  Though you'd just want to add the line number in the awk script.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#384 2020-05-14 09:12:41

kristoferus
Member
Registered: 2015-09-08
Posts: 27

Re: Dmenu Hacking Thread

Hi !

If i use

wmctrl -lx|awk '{print $3, $4, $5}' | dmenu -l 20 | wmctrl -lx | awk '{print $1}' | xargs wmctrl -i -a

not work if i select in dmenu

Thanks for help !

Last edited by kristoferus (2020-05-14 09:36:05)

Offline

#385 2020-05-14 11:59:12

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,517
Website

Re: Dmenu Hacking Thread

You're saying that doesn't work?  I wouldn't expect it to.  You need to get the result from dmenu to filter the output of wmctrl -lx, you can't just feed it into the stdin.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#386 2020-05-14 12:07:46

qinohe
Member
From: Netherlands
Registered: 2012-06-20
Posts: 1,494

Re: Dmenu Hacking Thread

Not entirely true;), this does work..

num=$(wmctrl -l | awk '{ $1=$2=$3=""; gsub(/^ */,""); printf "%3d - %s\n", NR, $0; }' | dmenu -l 20 | cut -d '-' -f 1)
[[ -z "$num" ]] && exit
wmctrl -l | sed -n "$num p" | cut -c -10 | xargs wmctrl -i -a

Offline

#387 2020-05-14 12:17:01

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,517
Website

Re: Dmenu Hacking Thread

sed + cut = sed.  I'm not sure what the input looks like, so there's probably something much less ugly that this for that third line:

wmctrl -l | sed -n "$num s/\(..........\).*/\1/p" | xargs wmctrl -i -a

Although I suspect what's wanted there is awk:

wmctrl -l | awk -v N=$num 'NR==N { print $1; }' | xargs wmctrl -i -a

Last edited by Trilby (2020-05-14 12:19:09)


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#388 2020-05-14 12:28:38

qinohe
Member
From: Netherlands
Registered: 2012-06-20
Posts: 1,494

Re: Dmenu Hacking Thread

I'll have a look at it but sure that line ain't gonna work... though I agree on the sed + cut;)

Offline

#389 2020-05-14 12:49:07

kristoferus
Member
Registered: 2015-09-08
Posts: 27

Re: Dmenu Hacking Thread

Yes the script work but without the first Argument like this

Pcmanfm       HOME to_dokument

Offline

#390 2020-05-14 12:57:32

qinohe
Member
From: Netherlands
Registered: 2012-06-20
Posts: 1,494

Re: Dmenu Hacking Thread

@Trilby, the point is OP is using 'sed -n "$num p"', print current pattern space.
Which leads to the answer '0x04400103' after using cut!
I don't know how to achieve that using awk have to take a look in the man;)

Offline

#391 2020-05-14 14:03:42

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,517
Website

Re: Dmenu Hacking Thread

What's the input?  sed -n "$num p" just prints the n'th line of input, then the cut prints just the first 10 characters of that line.  This is exactly what my sed command does.  The awk command prints the first column of the n'th line.  But again, as I don't know what the input is, I can't test the awk line.

No matter how you do it, you should only need one text processing tool between the first wmctrl and dmenu, then only one text processing tool in between the second and third calls to wmctrl.  Exactly what these should be can only be determined if someone actually provides example input and desired output.

You could also get rid of one of the calls to wmctrl if you stored the list in a variable.

Last edited by Trilby (2020-05-14 14:06:29)


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#392 2020-05-14 14:05:58

qinohe
Member
From: Netherlands
Registered: 2012-06-20
Posts: 1,494

Re: Dmenu Hacking Thread

darn, how could I think so complicated... here it is

num=$(wmctrl -l | awk '{ $1=$2=$3=""; gsub(/^ */,""); printf "%3d - %s\n", NR, $0; }' | $dmnews -l 20 | cut -d '-' -f 1)
wmctrl -l |  awk "/$num/"'{print $1}' | xargs wmctrl -i -a

Offline

#393 2020-05-14 14:07:47

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,517
Website

Re: Dmenu Hacking Thread

That will get all kinds of false positives.  You don't want to the second awk to match every line that coincidentally has the number selected in the window name / title.  Use NR not pattern matching.

And I doubt that will even work.  "num" is an ordinal number added to the wmctrl output in the first line.  It will not match anything from the second output of wmctrl.

Last edited by Trilby (2020-05-14 14:09:43)


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#394 2020-05-14 14:15:03

qinohe
Member
From: Netherlands
Registered: 2012-06-20
Posts: 1,494

Re: Dmenu Hacking Thread

Yes, you're right, the output of the wmctrl -l would be

0x01800022  0 asterope xterm
0x01a00022  0 asterope xterm
0x04200003  3 asterope Downloads
0x04400103  4 asterope pve-admin-guide.pdf - 65/462 (120 dpi)

so indeed checking can only be done trough the hexadecimal number

Offline

#395 2020-05-14 14:25:31

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,517
Website

Re: Dmenu Hacking Thread

*headdesk* no, that's not what I said at all.

These lines get the above input, format it for dmenu with ordinal line numbers, allow the user to select one in dmenu, then take the number of that result for the variable.  The third line gets the line based on that number and outputs the associated window ID. This can be piped to xargs/wmctrl again to select that window:

num=$(wmctrl -l | awk '{ $1=$2=$3=""; gsub(/^ */,""); printf "%3d - %s\n", NR, $0; }' | dmenu -l 20 | cut -d '-' -f 1)
[ -z "$num" ] && exit
wmctrl -l | awk -v N="$num" 'NR == N { print $1; }'    # | xargs ...

It would, however, be much safer to store the initial wmctrl output.  It'd like be trivially more efficient, but it will not completely break if any windows are mapped or removed while the script is running:

list=$(wmctrl -l)

num=$(echo "$list" | awk '{ $1=$2=$3=""; gsub(/^ */,""); printf "%3d - %s\n", NR, $0; }' | dmenu -l 20 | cut -d '-' -f 1)
[ -z "$num" ] && exit
echo "$list" | awk -v N="$num" 'NR == N { print $1; }' | xargs wmctrl -i -a

Last edited by Trilby (2020-05-14 14:39:27)


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#396 2020-05-14 15:12:00

qinohe
Member
From: Netherlands
Registered: 2012-06-20
Posts: 1,494

Re: Dmenu Hacking Thread

Ja oops, sorry for completely misunderstanding, I see ... now, this works very well yes.
I really need to do this more so I don't forget how to handle this for I already knew how to in the past:(
It's a shame but I have very little to practice this with for myself...

Offline

#397 2020-05-14 15:19:28

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,517
Website

Re: Dmenu Hacking Thread

That's why we get into pointless back and forths on a forum about the best way to write a silly script which most people wouldn't care about as long as it gets the job done.  Practice.  wink


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#398 2020-05-14 16:01:18

kristoferus
Member
Registered: 2015-09-08
Posts: 27

Re: Dmenu Hacking Thread

Thanks but again :-(

Yes the script work but without the first Argument like this

Pcmanfm       HOME to_dokument

Offline

#399 2020-05-14 16:18:11

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,517
Website

Re: Dmenu Hacking Thread

I'm not sure what that means.  Is that line what shows up in dmenu?  It shouldn't be.  What is the "first Argument" that is missing?


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#400 2020-05-14 16:37:27

kristoferus
Member
Registered: 2015-09-08
Posts: 27

Re: Dmenu Hacking Thread

Hi !

ok Sorry !

I have already a script that shows if i open dmenu the opened windows like your script and it works !

but if i open dmenu i see only the window title (perhaps sometimes more times):

like this

HOME to_dokument
HOME to_dokument


and i want that i see also which program is the opend window

like this: (only to see with wmctrl -lx)

Pcmanfm       HOME to_dokument
Urxvt              HOME to_dokument


Here also my try: (with wmctrl -l it works -> but nut with wmctrl -lx)

#!/usr/bin/bash
  
in=$(wmctrl -lx)
choice=$(echo "$in" | awk '{print $2, $3, $4}' | dmenu -l 20)

[[ -z "$choice" ]] && exit 1

echo "$in" | grep -F "$choice" | awk '{printf $1;exit}' | xargs wmctrl -i -a

Thanks

kristoferus

Last edited by kristoferus (2020-05-14 16:42:41)

Offline

Board footer

Powered by FluxBB