5

I need to programatically close a window in some program, based on the window title.

Is there a tool or a built-in system command I can use for that?

1 Answer 1

12

wmctrl can close a window based on a substring or exact match of the window title (wmctrl -c 'substring' or wmctrl -F -c 'exact match').

If you need more control, you can parse wmctrl -l, extract the matching window IDs and pass them to wmctrl -i -c. You can use wmctrl -x -l and match the class as well; in fact, I recommend it, since applications you haven't thought about might have windows with the same title.

2
  • Thanks a lot. However, when I'm connected via ssh wmctrl returns "Cannot open display". Is there a way around that?
    – GJ.
    Sep 19, 2010 at 6:08
  • @GJ: Programs normally connect to the display indicated by the DISPLAY environment variable. If you're connected via ssh and have X forwarding enabled, wmctrl acts on your display; without X forwarding DISPLAY won't be set. You'll also have to provide the cookie: that's a password that's generated when you log in and stored in the file indicated in the XAUTHORITY environment variable. Read this, and if you still can't figure it out, ask another question on acting remotely over an X display. Sep 19, 2010 at 10:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .