Johny Arduino Asked: 2015-07-11 02:34:37 +0800 CST2015-07-11 02:34:37 +0800 CST 2015-07-11 02:34:37 +0800 CST Get Active Window ID in Hex not Decimal 772 How to get the window ID of the focus(active) window in Hex ? wmctrl 3 Answers Voted Maythux 2015-07-11T02:47:11+08:002015-07-11T02:47:11+08:00 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. PatrickSteiner 2019-06-24T09:41:09+08:002019-06-24T09:41:09+08:00 Gives you 3 seconds time to change the window focus and prints afterwards the hexadecimal PID: ~$ sleep 3; printf 0x%x $(xdotool getactivewindow getwindowpid) justpeanuts 2022-09-04T00:56:22+08:002022-09-04T00:56:22+08:00 Use printf to convert decimal to hex. Eg. to get the window id of active window in hex use xdotool getactivewindow | xargs -I{} printf '%x\n' {}
Try this hack:
For example:
0x07600006 is the hex of active window which is the terminal in my case.
To be sure let's get it in decimal:
Now convert from decimal to hex:
It's the same.
Gives you 3 seconds time to change the window focus and
prints afterwards the hexadecimal PID:
Use printf to convert decimal to hex. Eg. to get the window id of active window in hex use