How to close only one window of an application?

233

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

Share:
233

Related videos on Youtube

morris
Author by

morris

Updated on September 18, 2022

Comments

  • morris
    morris over 1 year

    I learn ML from the book Introduction to Machine Learning with Python.

    When I try to import and run mglearn package I have the error:

    In:    import mglearn
    
    --------------------------------------------------------------------------
    ImportError                               Traceback (most recent call last)
    <ipython-input-35-26a0454c3f6e> in <module>
    ----> 1 import mglearn
    
    ~\Desktop\Introduction to Machine Learning with Python\ml_project\mglearn\__init__.py in <module>
    ----> 1 from .import plots
          2 from .import tools
          3 from .plots import cm3, cm2
          4 from .tools import discrete_scatter
          5 from .plot_helpers import ReBl
    
    ~\Desktop\Introduction to Machine Learning with Python\ml_project\mglearn\plots.py in <module>
          1 from .plot_linear_svc_regularization import plot_linear_svc_regularization
    ----> 2 from .plot_interactive_tree import plot_tree_progressive, plot_tree_partition
          3 from .plot_animal_tree import plot_animal_tree
          4 from .plot_rbf_svm_parameters import plot_svm
          5 from .plot_knn_regression import plot_knn_regression
    
    ~\Desktop\Introduction to Machine Learning with Python\ml_project\mglearn\plot_interactive_tree.py in <module>
          6 from sklearn.externals.six import StringIO  # doctest: +SKIP
          7 from sklearn.tree import export_graphviz
    ----> 8 from scipy.misc import imread
          9 from scipy import ndimage
         10 from sklearn.datasets import make_moons
    
    ImportError: cannot import name 'imread' from 'scipy.misc'   (c:\users\boni\appdata\local\programs\python\python37\lib\site-packages\scipy\misc\__init__.py)
    

    What I need to do for solve the problem?

    Thanks!

  • DOCff
    DOCff over 9 years
    Thank you for your help!However,that being said,it should be clarified that it kills the top instance of the programme you choose.
  • Jacob Vlijm
    Jacob Vlijm over 9 years
    @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?
  • DOCff
    DOCff over 9 years
    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)?
  • Jacob Vlijm
    Jacob Vlijm over 9 years
    @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.
  • DOCff
    DOCff over 9 years
    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'.
  • Jacob Vlijm
    Jacob Vlijm over 9 years
    @DOCff true, but then you need an extra step (first get the number). In principle the same: wmctrl (-i) -c.
  • Jacob Vlijm
    Jacob Vlijm over 9 years
    @DOCff see my edited answer.