3

I want to do some specific things in a bash script if the current window belongs to the Firefox class

  • I am aware of:
xdotool getactivewindow

and

xdotool search -class firefox

then I could do some test to know if the former result is in the latter list inside my bash script but:

  • Is there a better way to do that with xdotool?

NB: I am also aware that Autokey can do the trick but I cannot make it work with i3wm see that open issue

3

Since you are in Bash:

#!/bin/bash
curr=$(xdotool getactivewindow)
firefox=$(xdotool search -class firefox)
if [[ $firefox = *$curr* ]]; then
    echo Current window is of firefox class.
else
    echo Current window is not firefox class.
fi

The if clause tests whether $firefox contains an occurrence of $curr.

4
  • Is this conditioned by whether one works on Wayland or X11 ? Asking because less than a year ago, I saw that xdotools was kinda quirky in that sense (with Wayland)... and, yes, I know: a year is a looong time. – Cbhihe May 25 '20 at 11:34
  • 1
    Tx for the good help. I can use that but I am very surprised that there is no an easy way to do that with xdotools – pietrodito May 25 '20 at 11:39
  • 1
    @Cbhihe To be honest, I don't know, sorry. I have always only used X11. But notice that the manual says "xdotool - command-line X11 automation tool" and later "It does this using X11's XTEST extension and other Xlib functions." So I guess only X11. – Quasímodo May 25 '20 at 11:40
  • @pietrodito: consider unix.stackexchange.com/help/someone-answers if the answer is satisfactory for you... ;-) – Cbhihe May 25 '20 at 11:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.