Get Active Window ID in Hex not Decimal

How to get the window ID of the focus(active) window in Hex ?


Solution 1:

Try this hack:

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

For example:

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

0x07600006  0 19051  maythuxPC Gnome Terminal

0x07600006 is the hex of active window which is the terminal in my case.

To be sure let's get it in decimal:

$ xdotool getactivewindow 
123731974

Now convert from decimal to hex:

$ printf 0x%x 123731974
0x7600006

It's the same.

Solution 2:

Gives you 3 seconds time to change the window focus and
prints afterwards the hexadecimal PID:

~$ sleep 3; printf 0x%x $(xdotool getactivewindow getwindowpid)