5

I know that if I get the sid through :

ps -ax | grep firefox

and use :

kill -9 "sid"

I will close all the windows of the program.

How can I close only one window of an application running through the terminal?

0

1 Answer 1

12

Probably the easiest option is using wmctrl -c. You might have to install it first:

~$ sudo apt-get install wmctrl

then to close a window named "example" (no matter what application it belongs to), use the command:

~$ wmctrl -c "example"

More options

However, there are many more options to close a specific window, depending on your "angle of incidence".

A few examples:

  1. To close a specific window by clicking on it:

    ~$ wmctrl -c :SELECT:
    [then click on the window to be closed]
    
  2. To close a specific window by its numeric id:

    ~$ wmctrl -ic <numeric_id>
    
  3. To close the active window:

    ~$ wmctrl -c :ACTIVE:
    
  4. To use the pid to get a list of windows, owned by a specific application (e.g. gedit):

    ~$ pidof gedit
    22576
    
    ~$ wmctrl -l -p | grep 22576
    0x04600085  0 22576  jacob-System-Product-Name get.sh (~/Bureaublad) - gedit
    0x0461aee4  0 22576  jacob-System-Product-Name verhaal (~/Bureaublad) - gedit
    0x0461b0a1  0 22576  jacob-System-Product-Name *Niet-opgeslagen document 1 - gedit
    

    then close the specific window get.sh by either:

    wmctrl -c get.sh
    

    or:

    wmctrl -ic 0x04600085
    
  5. If you know only part of the window name, e.g. there is a window; monkey eats banana.txt, you know it has banana in its name,

    • first bring the window to front:

      wmctrl -a banana
      
    • then decide if you want to close the window (as active window for example)

options are numerous, see also man wmctrl. man wmctrl

7
  • Thank you for your help!However,that being said,it should be clarified that it kills the top instance of the programme you choose.
    – DOCff
    Nov 25, 2014 at 1:44
  • @DOCff I am not sure I understand what you mean. If I have two (e.g.) gedit windows opened: (e.g.) "monkey", "banana", then wmctrl -c "banana" kills the "banana" window, even if it is in the background. could you give an example of your windowname and the command? Do you mean firefox or thunderbird, a window or a tab? Nov 25, 2014 at 7:02
  • I meant for example,if you have two instances of the same program e.g. firefox and input wmctrl -c firefox you'll kill the top instance of the program.Is there any way to choose more specifically(without renaming the window)?
    – DOCff
    Nov 25, 2014 at 15:53
  • @DOCff but you do have the window name of the specific window, that is your key to close specifically one window of an application, do not use the application name, but the specific window name. Nov 25, 2014 at 17:07
  • Ok,thanks a lot.But another way I figured out as well was getting the numeric value of the window with wmctrl -l and using wmctrl -ic 'window's numeric value'.
    – DOCff
    Nov 27, 2014 at 1:18

You must log in to answer this question.

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