Is there a gnome 3 extension or a fedora 25 shortcut to close all opened applications in a workspace? (Closing the workspace itself by pressing an X for example).
I've seen that functionality somewhere long time ago, forgot where, but it's not available in fedora by default.
Best Answer
The answer below was written and tested on Gnome3 / Ubuntu. Please mention if you run into issues when running it on Fedora / Gnome.
Script to close all application windows on a specific workspace in Gnome
The script below will close all windows on a specific workspace, with two options:
When run without arguments, it closes all windows on the current workspace, e.g.:
when run with a specific workspace as argument, it will close all windows on that workspace, e.g.:
will close all applications on workspace 1. Note that the first workspace has index 0
The script
How to use
close_wins.py
Now test- rune the script from a terminal window, with the targeted workspace as argument, e.g.:
to gracefully close all windows on workspace 3 (0 = worspace 1)
To close all windows on the current workspace, run it without arguments:
If all works fine, add it to a shortcut key: choose: System Settings > "Keyboard" > "Shortcuts" > "Custom Shortcuts". Click the "+" and add the command:
...or run it in any other way you'd prefer.
Explanation
The command
wmctrl -lG
will give us information on the currently opened windows. The output looks like:From the second column, we can retrieve the window's location:
The
2
means the window is on workspace 3, since0
refers to the first workspace.If the script runs with the workspace as argument, the script parses out the corresponding window- id's and subsequently closes them gracefully with the command (e.g.):
If the script runs without the workspace as argument, the script retrieves the current workspace from the command:
and subsequently uses the current workspace internally as argument.