You are not logged in.

#401 2020-05-14 16:42:23

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

Re: Dmenu Hacking Thread

Trilby wrote:

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

Quite right you are, I should, practice;)

About the script, it works as intended, a numbered list of programs in dmenu to choose from.

@kristoferus, try the last the last lines from #395 should work!

Offline

#402 2020-05-14 16:44:57

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

Re: Dmenu Hacking Thread

Ok, so again, what's the output of wmctrl -lx, the awk script will need to be adjusted for the different output.

I'd guess this might do:

list=$(wmctrl -lx)

num=$(echo "$list" | awk '{ $1=$2=""; 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

But this is a wild guess.  I don't use wmctrl.  I can polish the text processing, but if you don't provide the actual input I'm just guessing what it might look like.

Last edited by Trilby (2020-05-14 16:53:40)


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

Offline

#403 2020-05-14 16:48:20

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

Re: Dmenu Hacking Thread

wmctrl -l

0x0160000a  0 HOME @HOME:~
0x00a00001  1 HOME Dmenu Hacking Thread (Page 17) / Programming & Scripting / Arch Linux Forums - Chromium
0x01c00003  3 HOME

wmctrl -lx

0x0160000a  0 urxvt.URxvt           HOME@HOME:~
0x00a00001  1 chromium.Chromium     HOME Dmenu Hacking Thread (Page 17) / Programming & Scripting / Arch Linux Forums - Chromium
0x01c00003  3 pcmanfm.Pcmanfm       HOME

Last edited by kristoferus (2020-05-14 16:56:04)

Offline

#404 2020-05-14 16:50:48

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

Re: Dmenu Hacking Thread

See my edit, I believe my guess was right.


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

Offline

#405 2020-05-14 16:53:48

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

Re: Dmenu Hacking Thread

no it shows now:

2 - HOME  @HOME:~

Last edited by kristoferus (2020-05-14 16:55:39)

Offline

#406 2020-05-14 16:57:35

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

Re: Dmenu Hacking Thread

My script with the wmctrl -lx output you provided puts this in dmenu:

  1 - urxvt.URxvt HOME@HOME:~
  2 - chromium.Chromium HOME Dmenu Hacking Thread (Page 17) / Programming & Scripting / Arch Linux Forums - Chromium
  3 - pcmanfm.Pcmanfm HOME

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

Offline

#407 2020-05-14 17:00:23

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

Re: Dmenu Hacking Thread

Sorry Yes you are right -> mybe a copy and paste mistake !

THANKS cool :-)

Offline

#408 2020-05-16 07:47:12

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

Re: Dmenu Hacking Thread

@Trilby

Is it also possible to adapt the script that see it in dmenu like this ?

  1 - URxvt HOME@HOME:~
  2 - Chromium HOME Dmenu Hacking Thread (Page 17) / Programming & Scripting / Arch Linux Forums - Chromium
  3 - Pcmanfm HOME

Offline

#409 2020-05-16 12:15:00

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

Re: Dmenu Hacking Thread

Just replace the gsub in the first awk with this:

gsub(/^[^\.]*\./,"");

This replaces everything up to the first "." rather than just the spaces at the start of the line.


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

Offline

#410 2020-05-16 13:50:43

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

Re: Dmenu Hacking Thread

@Trilby

Thanks for the help -> perfect !

Last edited by kristoferus (2020-05-16 13:50:58)

Offline

#411 2020-05-16 16:08:36

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

Re: Dmenu Hacking Thread

@Trilby

Sorry again

The hostname is also not nessacery in the usage (HOME)

2 - chromium.Chromium HOME Dmenu Hacking Thread (Page 17) / Programming & Scripting / Arch Linux Forums - Chromium

Is this also possible ?

Thanks !

Offline

#412 2020-05-16 16:45:46

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

Re: Dmenu Hacking Thread

I've been assuming there's a typo in the example output of wmctrl I've been working with as there are different numbers of columns.  If the Urxvt line actually has "HOME @HOME:~" or perhaps "HOME HOME@HOME:~" then this is very easy, just blank one more column in the start of the awk thread.  Please take some time to read up on awk to know what it is doing with that script and you'll be able to adjust this all you'd like.

While I've not been through his awk tutorial, Bruce Barnett's sed tutorial is great, so I suspect the linked awk tutorial should be as well.  It is, however, written for those with a bit of *nix background.  If you don't have that yet, I'd recommend working through Ryan's tutorials as they are an excellent foundation for those with little to no backround in unix/linux.

Last edited by Trilby (2020-05-16 16:48:57)


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

Offline

#413 2020-05-16 18:40:47

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

Re: Dmenu Hacking Thread

@Trilby

Thanks i have solve it :-)

awk '{ $1=$2=$4=""....

Last edited by kristoferus (2020-05-16 18:47:28)

Offline

#414 2020-05-16 19:09:46

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

Re: Dmenu Hacking Thread

Nicely done.


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

Offline

#415 2020-06-22 18:52:20

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

Re: Dmenu Hacking Thread

Hi !

I use this script to search sezific files and open with xdg-open -> it works -> but files with an ' in the filename doesnt work:

fd -a -e "pdf" -e "jpg" -e "txt" -e "mp3" -e "mkv" -e "mp4" . ~/ | dmenu  -l 20 -i | (nohup xargs -I{} xdg-open "{}" >/dev/null 2>&1 &) 

Thanks !

Offline

#416 2020-06-22 19:02:48

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

Re: Dmenu Hacking Thread

Why the xargs in a subshell at the end.  Dmenu can only return one result, right?  So just get rid of that bit at the end and just open the result with xdg-open.


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

Offline

#417 2020-06-22 20:27:56

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

Re: Dmenu Hacking Thread

like this it doesnt work :

fd -a -e "pdf" -e "jpg" -e "txt" -e "mp3" -e "mkv" -e "mp4" . ~/ | dmenu  -l 20 -i | xargs xdg-open

Offline

#418 2020-06-22 20:54:02

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

Re: Dmenu Hacking Thread

If you want to use xargs:

... | xargs -I{} xdg-open "{}"

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

Offline

#419 2020-06-23 07:43:41

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

Re: Dmenu Hacking Thread

Thanks !

with this command it works:

fd -a -e "pdf" -e "jpg" -e "txt" -e "mp3" -e "mkv" -e "mp4" . ~/ | dmenu  -l 20 -i | xargs -0 -I{} xdg-open "{}"

Offline

Board footer

Powered by FluxBB