Bra*_*iam 17 command-line scripting x11 window window-management
我在 Ask Ubuntu Quit all instances of gnome-terminal
via a command上回答,但正如你们所有人都可以阅读的gnome-terminal
那样,似乎没有SIG
我可以用来模拟这个“关闭”事件的电话。所以这让我想问,在 GNOME/KDE/LXDE/{put your window/desktop manager/environment here} 中有没有办法模拟“点击关闭按钮”事件?我已经阅读 了可能与此有关的不同 问题 ,但不要回答这个问题。
我正在寻找的是一个全局命令(如果存在)在不同场景中执行此操作。如果不存在,请解释“关闭”按钮的工作原理。
可能的用途:
gnome-terminal
实例,但如果有子进程仍在运行,则警告我。slm*_*slm 19
我相信相关的手册页是XKillClient。您可以xdotool
像这样模拟从终端单击的关闭按钮。
假设我有一个gnome-terminal
开放的,它的名字是“saml@grinchy:/home”。
获取窗口ID
$ xdotool search --name "saml@grinchy:/home"
96488188
Run Code Online (Sandbox Code Playgroud)发送Alt+F4
$ xdotool windowactivate --sync 96488188 key --clearmodifiers \
--delay 100 alt+F4
Run Code Online (Sandbox Code Playgroud)您可以通过将第一个命令嵌入到第二个命令中来将它们组合在一起:
$ xdotool windowactivate --sync $( ...1st command...) key --clearmodifiers \
--delay 100 alt+F4
Run Code Online (Sandbox Code Playgroud)
您可以通过让xdotool
两者同时进行来拯救自己:
$ xdotool search --name "saml@grinchy:~" key alt+f4
Run Code Online (Sandbox Code Playgroud)
您可以调整我提供的内容以在具有相同名称的 Windows 上运行它:
$ xdotool search --name "saml@grinchy:~"
96488779
96468996
Run Code Online (Sandbox Code Playgroud)
或者在 windows 上通过其他属性。您可以使用xwininfo
来了解有关特定窗口的更多信息。运行它,然后点击感兴趣的窗口:
$ xwininfo
xwininfo: Please select the window about which you
would like information by clicking the
mouse in that window.
xwininfo: Window id: 0x5c04d4b "saml@grinchy:~"
Absolute upper-left X: 14
Absolute upper-left Y: 74
Relative upper-left X: 14
Relative upper-left Y: 74
Width: 941
Height: 361
Depth: 32
Visual: 0x62
Visual Class: TrueColor
Border width: 0
Class: InputOutput
Colormap: 0x5c00003 (not installed)
Bit Gravity State: NorthWestGravity
Window Gravity State: NorthWestGravity
Backing Store State: NotUseful
Save Under State: no
Map State: IsViewable
Override Redirect State: no
Corners: +14+74 -485+74 -485-465 +14-465
-geometry 132x24+14+74
Run Code Online (Sandbox Code Playgroud)
处理 X11 窗口时其他有用的工具是xdpyinfo
& xprop
。xdpyinfo
可用于查找有关 X 服务器的信息。所以你可以找出哪个窗口有焦点:
$ xdpyinfo |grep focus
focus: window 0x5c00005, revert to Parent
Run Code Online (Sandbox Code Playgroud)
xprop
并且xwininfo
可以进行-id
切换,以便您可以向他们提供您感兴趣的窗口 ID,而不必单击它:
$ xprop -id 0x5c00001|grep -i class
WM_CLASS(STRING) = "gnome-terminal", "Gnome-terminal"
Run Code Online (Sandbox Code Playgroud)