开发者

using wmctrl to close windows

开发者 https://www.devze.com 2023-02-17 18:41 出处:网络
Can I close a window using wmctrl that is running in wine on Ubuntu? For context: $ wmctrl -m Name: compiz

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 Edg开发者_如何学运维e 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.


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


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号