How to get the window ID of the focus(active) window in Hex ?
Asked
Active
Viewed 5,996 times
3 Answers
10
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.
Maythux
- 87,123
1
Gives you 3 seconds time to change the window focus and
prints afterwards the hexadecimal PID:
~$ sleep 3; printf 0x%x $(xdotool getactivewindow getwindowpid)
PatrickSteiner
- 171
0
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' {}
justpeanuts
- 1
- 1