Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

up vote 8 down vote accepted

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.

share|improve this answer
    
Thanks a lot. However, when I'm connected via ssh wmctrl returns "Cannot open display". Is there a way around that? –  GJ. Sep 19 '10 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. –  Gilles Sep 19 '10 at 10:49

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.