我需要活动或聚焦的窗口的 id。我尝试使用xdotool
命令。有命令:
xdotool getactivewindow
Run Code Online (Sandbox Code Playgroud)
结果保存到窗口堆栈中。我想从这个窗口堆栈中获取 widnow id。命令
xdotool getactivewindow getwindowpid
Run Code Online (Sandbox Code Playgroud)
不满足我。我不想通过进程 ID 获取窗口 ID。
Vol*_*gel 11
我想xdotool getactivewindow
这就是你想要的——你试过了吗?
如果命令行上没有其他 xdotool 子命令,它会打印窗口 ID(来自窗口堆栈)。
在xdotool getactivewindow getwindowpid
例如, getactivewindow
把窗口堆栈上的ID,并getwindowpid
使用该ID来查询PID。请注意,在终端中运行该命令将始终返回终端窗口的 ID,因为它处于活动状态。为了从另一个窗口获取 ID,请尝试sleep 2s && xdotool getactivewindow
在两秒的时间跨度内选择感兴趣的窗口。
xdotool
与其他窗口处理工具一起
使用时会出现复杂情况:
虽然xdotool
输出使用十进制数作为windwo ids,但大多数其他工具使用十六进制数作为输出(它们通常支持这两种输入)。
例如,如果您找到一个带有 的窗口xdotool getactivewindow
,您将不会在xwininfo -root -tree
列出所有窗口的的输出中找到结果。需要先转换为十六进制数:
$ xdotool getactivewindow
69206716
$ printf 0x%x 69206716
0x42002bc
$ xwininfo -root -tree | grep 0x42002bc
0x42002bc (has no name): ("konsole" "Konsole") 1154x781+0+0 +1289+498
Run Code Online (Sandbox Code Playgroud)
十进制转十六进制:
printf 0x%x 69206716
Run Code Online (Sandbox Code Playgroud)
十六进制转十进制:
printf %i 0x42002bc
Run Code Online (Sandbox Code Playgroud)