使用 wmctrl 关闭窗口

发布于 2024-10-22 18:42:59 字数 865 浏览 6 评论 0原文

我可以使用 Ubuntu 上 wine 中运行的 wmctrl 关闭窗口吗?

对于上下文:

$ wmctrl -m
Name: compiz
Class: N/A
PID: N/A
Window manager's "showing the desktop" mode: OFF

另外:

$ wmctrl -l
0x0240a3be -1 mjol N/A
0x02000003  0 mjol Top Expanded Edge Panel
0x0200004c  0 mjol Bottom Expanded Edge Panel
0x01e00024  0 mjol x-nautilus-desktop
0x04800253  0 mjol using wmctrl to close windows - Stack Overflow - Google Chrome
0x03c0c8c3  0 mjol Terminal
0x03c53f25  0 mjol Terminal
0x04400001  0 mjol Untitled - SketchUp
0x04400003  0 mjol Instructor
0x04400009  0 mjol SketchUp

我想关闭的窗口是最后一个:

0x04400009  0 mjol SketchUp

我已经尝试过以下操作:

$ wmctrl -c "SketchUp"

$ wmctrl -c 0x04400009

$ wmctrl -i 0x04400009

$ wmctrl -c -i 0x04400009

但没有任何效果。

Can I close a window using wmctrl that is running in wine on Ubuntu?

For context:

$ wmctrl -m
Name: compiz
Class: N/A
PID: N/A
Window manager's "showing the desktop" mode: OFF

Also:

$ wmctrl -l
0x0240a3be -1 mjol N/A
0x02000003  0 mjol Top Expanded Edge Panel
0x0200004c  0 mjol Bottom Expanded Edge Panel
0x01e00024  0 mjol x-nautilus-desktop
0x04800253  0 mjol using wmctrl to close windows - Stack Overflow - Google Chrome
0x03c0c8c3  0 mjol Terminal
0x03c53f25  0 mjol Terminal
0x04400001  0 mjol Untitled - SketchUp
0x04400003  0 mjol Instructor
0x04400009  0 mjol SketchUp

The window I want to close is the last one:

0x04400009  0 mjol SketchUp

I've tried the following:

$ wmctrl -c "SketchUp"

$ wmctrl -c 0x04400009

$ wmctrl -i 0x04400009

$ wmctrl -c -i 0x04400009

But nothing works.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

旧伤还要旧人安 2024-10-29 18:42:59

也许有点晚了,但现在第一次看到。
阅读 wmctrl 的信息,它说正确的语法是 actions 之前的“options”,并且 -i 是一个选项,-c 是一个选项。行动。尝试 wmctrl -i -c 0x04400009

Maybe a little late, but first seen now.
Reading the info for wmctrl, it says that the correct syntax is 'options' before actions, and -i is an option, -c an action. Try wmctrl -i -c 0x04400009

戏剧牡丹亭 2024-10-29 18:42:59

我也有同样的问题,刚刚找到了如何做!

下面的一行代码将优雅地关闭所有 Google Chrome 窗口

wmctrl -lix |grep 'Google-chrome'|cut -d ' ' -f 1 |xargs -i% wmctrl -i -c %

说明:

wmctrl -lix 列出所有窗口,包括其 ID 和类

grep 'Google-chrome' grep 仅具有 Google-chrome 类的窗口(这很重要,因为当您使用带有应用程序/快捷方式选项的网站时,它会获得自己的类,例如 'calendar.google.com.Google- chrome'

cut -d ' ' -f 1 剪切输出以仅获取 ID 列

xargs -i% wmctrl -i -c % 将每个 ID 传递给 wmctrl 使用 ID 选项 -i 并关闭命令 -c

注意: xargs 仅在我使用 -i 选项指定替换字符串时才起作用,否则它只会作用于第一个项目。

I was having the same question and just found how to do it!

Here's the one-liner that will gracefully close all Google Chrome windows:

wmctrl -lix |grep 'Google-chrome'|cut -d ' ' -f 1 |xargs -i% wmctrl -i -c %

Explanation:

wmctrl -lix list all windows including their Id and Class

grep 'Google-chrome' grep only windows with Google-chrome class (this is important because when you use a site with the app/shortcut option it gets it own class like 'calendar.google.com.Google-chrome'

cut -d ' ' -f 1 cuts the output to get only the IDs column

xargs -i% wmctrl -i -c % passes each ID to the wmctrl using the ID option -i and close command -c

Note: the xargs only worked when I used the -i option to specify replace-string. Otherwise it would only act on the first item.

俯瞰星空 2024-10-29 18:42:59

根据手册页,您应该选择< /strong> 窗口首先使用选择选项,例如 -r-a,例如:

$ wmctrl -l      
0x01800006  0 hostname Terminal - byobu

$ wmctrl -a Terminal

这里确实选择了(并且由于 -a< /code>) 终端窗口。

然后你可以使用调整大小/移动选项,例如 -egravity,X,Y,width,height

至于你的问题,我刚刚测试了这个:

$ wmctrl -l                              
0x01800006  0 machine_hostname - byobu
0x06800002  0 moe Microsoft Excel - Classeur1

Excel(显然在 Wine 中运行)在以下情况下正常关闭我

$ wmctrl -c Microsoft

此处输入了大量附加信息。

According to the man page, you should select the window first using a select option, like -r and -a, exemple :

$ wmctrl -l      
0x01800006  0 hostname Terminal - byobu

$ wmctrl -a Terminal

Here indeed selects (and raises + focus due to -a) the terminal window.

Then you can use a resize / move option such as -e gravity,X,Y,width,height

As for your question, I just tested this :

$ wmctrl -l                              
0x01800006  0 machine_hostname - byobu
0x06800002  0 moe Microsoft Excel - Classeur1

And Excel (obviously running in Wine) closed gracefully when I entered

$ wmctrl -c Microsoft

Plenty of additional info here.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文