The linux commandline tool wmctrl allows you to list all windows, or all desktops, among other things. In the desktop-listing mode, the current desktop is marked with an asterisk.

I need a tool that can figure out the currently active window's title. Unfortunately, wmctrl doesn't have a helper that does this - despite it knowing which window is currently active (see :ACTIVE: marker).

Is there another commandline tool that can give me the window id and/or window title of the current window?

link|improve this question

44% accept rate
feedback

1 Answer

There is, but no short answer or solution.

wmctrl -lp | grep `echo $(xprop -root | grep _NET_ACTIVE_WINDOW | head -1 | awk '{print $5}' | sed 's/,//' | sed 's/^0x/0x0/')`

result:

0x03800004 0 16459 xxxxxxxxxx /bin/bash

In use:

for x in `seq 1 10`; do sleep 5; wmctrl -lp | grep `echo $(xprop -root | grep _NET_ACTIVE_WINDOW | head -1 | awk '{print $5}' | sed 's/,//' | sed 's/^0x/0x0/')`; done

0x03800004 0 16459 xxxxxxxxxx /bin/bash
0x020000a4 0 13524 xxxxxxxxxx linux - Detecting currently active window - Super User - Mozilla Firefox (Build 20120129142219)

link|improve this answer
This looks like a good solution, didn't know about the xprop utility. In the meantime, I've patched wmctrl to provide such an option and sent it to the author. Unfortunately, I didn't get a response yet. – Dave Vogt Feb 22 at 9:15
feedback

Your Answer

 
or
required, but never shown

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