Ubuntu – keyboard shortcut for minimizing all windows except the active one

shortcut-keys

When opening programs like GIMP, I find having background windows open distracting because GIMP has three separate windows associated with it.

It's a burden to have to go to every other non-Gimp window manually to minimize it. What I need is a keyboard shortcut in Ubuntu that matches Windows' Super + Home shortcut. One that minimizes all windows except the active one.

Is it possible to achieve this behavior in Ubuntu?

Best Answer

It is possible to achieve this with a python script. The script requires python-wnck and python-gtk to be installed in order to work, although I think these are installed by default anyway.

Copy and paste this into a text editor and save in a sensible place (eg. as minimise.py in your home folder):

#!/usr/bin/env python
import wnck
import gtk

screen = wnck.screen_get_default()

while gtk.events_pending():
    gtk.main_iteration()

windows = screen.get_windows()
active = screen.get_active_window()

for w in windows:
    if not w == active:
        w.minimize()

You can then set up the keyboard shortcut by opening Keyboard Shortcuts.

Keyboard Shortcuts in Dash

Click on Add to create a new shortcut.

Keyboard Shortcuts window

Use the command bash -c 'python ~/minimise.py' (this is assuming you saved it as minimise.py in your home folder).

create shortcut

You can then assign your preferred keyboard combination to this action.

The script will minimise all non-active windows. I don't think this is very useful for your use case because you will want to have all of the Gimp windows open. You can use a slightly different script to minimise all windows that aren't from the current application instead:

#!/usr/bin/env python
import wnck
import gtk

screen = wnck.screen_get_default()

while gtk.events_pending():
    gtk.main_iteration()

windows = screen.get_windows()
active_app = screen.get_active_window().get_application()

for w in windows:
    if not w.get_application() == active_app:
        w.minimize()
Related Question