I think xdotool getactivewindow
is what you want - did you try it?
It prints the window id (from the window stack) if there are no further xdotool subcommands on the command line.
In xdotool getactivewindow getwindowpid
for example, getactivewindow
puts the id on the window stack, and getwindowpid
uses this id to query the PID. Note that running that command in the terminal will always return the ID of the terminal window, because it is active. In order to get the ID from another window try sleep 2s && xdotool getactivewindow
and select the window of interest in the two seconds time span.
There is a complication when using xdotool
with other tools for window handling:
While xdotool
output uses decimal numbers for windwo ids, most other tools use hexadecimal numbers for output (they support both for input usually).
For example, if you find a window with xdotool getactivewindow
, you will not find the result in the output of xwininfo -root -tree
, that lists all windows. It needs to be converted to a hexadecimal number first:
$ xdotool getactivewindow
69206716
$ printf 0x%x 69206716
0x42002bc
$ xwininfo -root -tree | grep 0x42002bc
0x42002bc (has no name): ("konsole" "Konsole") 1154x781+0+0 +1289+498
Converting decimal to hexadecimal:
printf 0x%x 69206716
Converting hexadecimal to decimal:
printf %i 0x42002bc
I've figured it out myself:
xdotool mousemove 500 100 getmouselocation --shell mousemove restore
This briefly moves the mouse to the specified position (x=500, y=100 in this example), prints WINDOW
which is the windowid
on top, then moves the mouse back.
This is probably not the intended usage of mousemove, but I could not find any better way to do what I wanted.
Best Answer
My xdotool help informs me that your two switches are the same (xdotool version 3.20150503.1),
and as such doesn't do anything. My xdotool does the same as yours with replacing the window stack, so I did it with a shell script. A shell script doing what you want is delivered below:
The asterisks in the if statement is there in order to do a substring match for
TODO
, so that it can occur wherever in the title.