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?
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"
However, there are many more options to close a specific window, depending on your "angle of incidence".
A few examples:
To close a specific window by clicking on it:
~$ wmctrl -c :SELECT:
[then click on the window to be closed]
To close a specific window by its numeric id:
~$ wmctrl -ic <numeric_id>
To close the active window:
~$ wmctrl -c :ACTIVE:
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
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
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
wmctrl -c firefox
you'll kill the top instance of the program.Is there any way to choose more specifically(without renaming the window)?
wmctrl -l
and using wmctrl -ic 'window's numeric value'
.