Quit all instances of `gnome-terminal` via a command
Despite it's name, killall
(and kill
) sends SIGTERM
signal to all the process with the same name, also you can personalize the signal sent with the -s
switch. So, instead using killall gnome-terminal
you can use killall -s {signal} gnome-terminal
.
I haven't find out what signal can be interpreted as click at the close button, but my guess is, that it's a GUI hook that trigger such behavior. In gnome2 there was a "Close all" option in the task list, but in gnome3 seems such option it's lost.
After a lengthy discussion over U&L
With the help of slm who gave me the idea, you can simulate the alt + F4 key combination on several instances of gnome-terminal using xdotool search --name terminal key --window %@ alt+F4
. You must be sure you have installed xdotool
using:
sudo apt-get install xdotool
But, lets me explain in detail:
search
do a search of all window with a determinated characteristics. --name
switch will look for windows with the content on the title bar. key
tells xdotool
that we are going to use keyboard commands. --window
tells to use a determinated ID for the key
command, if not set it will use %1
from the stack. %@
means to use all the stack of ID's. alt+F4
tells the key combination to send.
More information:
www.semicomplete.com/projects/xdotool/xdotool.xhtml
Related videos on Youtube
Comments
-
Jez W over 1 year
This is half "this'd be useful for me" and half "hobby project" - I was wondering if it's possible to send a command via a
gnome-terminal
that will quit all instances of a program without usingkillall
.Essentially I'd like to write a script, which I will put in my
$PATH
, that will try and exit all open terminal windows as if the close button had been clicked on each, rather than killing. The reason being that I have a terrible habit of opening many terminal windows at once and it's a hassle to go through each of them and quit all of them individually. Simply typingexeunt
(because let's face it, there's no better name for a command to "exit all") and having them all quit would be far better for me. However, I don't want to accidentally close any programs that are still running from within a terminal - I still want to see any "There is still a process running in this terminal" prompts, so the commandkillall gnome-terminal
would be out of the question.The ideal I suppose would be a command-line / bash equivalent of rightclicking on the Dash icon and pressing "quit". Possibly a slightly unorthodox request, but I'd be interested to know if it's somehow possible.
-
Bramski over 10 yearskillall (and kill) only send an actual KILL signal when you explicitly tell it to do so, the default signal is TERM(inate). You can look up all the signals in
man 7 signal
. -
Jez W over 10 yearsInteresting. Is there a signal that I can send that'd be interpreted as an alt-f4 or a "close", though? Otherwise the only way I can think of along these lines would be to delve into the gnome terminal source and put in a handler for SIGUSR1 / 2 to tell it to close cleanly, by the looks of that list.
-
Jez W over 10 yearsSorry, been away for a while. Seems like a very nice solution, but doesn't quite seem to work as expected (by the look of things it sends an alt-f4 signal for each open terminal window, but doesn't switch between them in between - so what happens is the "Close this window?" prompt flashes on and off for a little bit for the terminal window in which the command is run (as
xdotool
counts as a running program while the command is still running) -
Braiam over 10 years@JezW Well, you actually asked how to "Quit all instances of
gnome-terminal
via a command" which this answer do at the perfection. If you want to do something more elaborate, ask another question or read the manual ;). -
Jez W over 10 yearsIt doesn't, though. When I type it, it brings up a "close this window?" prompt for the active terminal window (and even then only if there are an odd number of terminals open - if it's an even number the prompt flickers on and off and disappears) - it doesn't have any effect on any of the other open windows...
-
Braiam over 10 yearsDid you noticed that if your "terminals" don't have the name "terminal" in the title it wouldn't work. Ex. if your terminals has "JezW@pc" in the title, you should run
xdotool search --name JezW key --window %@ alt+F4
to close them all. If some application changes this, then you should use--class
or--classname
accordingly. I only offered an example that you should modify to fit your requirements. Another example, for mexdotool search --name "gedit|terminal|office" key --window %@ alt+F4
will close any window that has gedit, terminal or office in their name. -
Braiam over 10 years@JezW check your selectors, since something must be missing.
-
Jez W over 10 yearsPutting my username instead of the word "terminal" does exactly the same thing - it seems to (in effect) count how many terminal windows are open, and then presses alt+f4 that many times (i.e. with 3 open, the "Close this terminal?" prompt for the active terminal appears, disappears and then reappears)
-
Braiam over 10 yearsCould you post what
xdotool search --name JezW
outputs. In my case I fired 10 terminals, then usedbash
to pin them, and the behavior you describe doesn't happen. Try adding--sync
to the command. Also,xdotool getactivewindow
to check the active number and compare it to your list. If you want you can Ask Ubuntu Chat with me, to don't make this comments too extended.