I worked out an awesome little tip/trick and wanted to share it somewhere! It should work on a variety of linux distros, probably most common ones out there.
This started out with the GNOME extension
Toggle Nautilus. Its Super+E toggle isn't working in Debian Jessie/GNOME 3.14, and in Debian's Wheezy I was used to this super quick and easy toggle for Nautilus rather than setting some custom hotkey in GNOME Keyboard preferences that merely starts a NEW Nautilus window (not bring up the existing one) and so accumulating 20 Nautilus windows in the process if I'm not careful.
I had already used
AutoKey for other cool remappings (like mapping my macbook's power key to <delete>!), and had a bit of experience using xdotool for scripting up window navigation and the like, so with a bit of determination and 45 mins of googling and trial and error, little non-programmer me cracked it (ah the power of code)!!! A full toggler that opens a new window of the app if there isn't currently one, brings up the existing window if there is, and minimizes ('hides') that window if you're currently IN it - and it seems to work flawlessly.
So:
apt-get install autokey-gtk xdotool wmctrl (or for its 'KDE version' the repo says autokey-qt, I haven't tried it in KDE yet, or otherwise in general
build from source), and make a new 'Script' with this code and map it to whatever hotkey you want for it:
Code:
#AutoKey script to toggle any windowed application, Nautilus as the example. Requires xdotool and wmctrl.
import subprocess
command = 'wmctrl -lx'
output = system.exec_command(command, getOutput=True)
if 'nautilus.Nautilus' in output:
winClass = window.get_active_class()
if winClass == 'nautilus.Nautilus':
system.exec_command("xdotool windowminimize $(xdotool getactivewindow)")
else:
system.exec_command("wmctrl -x -a nautilus.Nautilus")
else:
system.exec_command("nautilus")
#end script
That's basically it! If anyone has any improvements/ideas it'd be great but in my testing it works lightning fast and flawlessly so far! BTW, KDE/other desktops may have their OWN equally powerful way to 'toggle the window of a given application (KDE tends to blow me away in how feature-rich it is with window management!), but either way, I think this is one great way to do it in KDE, GNOME and I assume more! AutoKey rocks!
I successfully tested this with:
- Nautilus (I now map it to Super+E)
- gedit (I now map it to Super+G)
- Terminal (I now map it to Super+T)
- AutoKey itself
- Debian's Iceweasel
- Recoll (I now map it to Super+F!)
The only application I've tried that is only partially working (bringing it up works but the xdotool minimize command doesn't), is a java program. But I'll try to achieve it another way, I'm sure with a minor modification it can also minimize via the hotkey just fine.
And another detail: if the app has multiple windows, it seems to work fine by just opening the 'first' one without worrying about the others, and if you're currently in a second, third, fourth etc window of that given app (to toggle it 'off'), it either just minimizes that single window if that's all that was 'unminimized', or if others are still 'unminimized' it actually brings them up one by one after the other and minimizes them all as you go! Which to me is desirable behavior!
I suppose you could easily modify it to minimize ('hide') ALL of the given app's (wm_class) windows instead of just the current one, too.
long live coding!
Peace out