Linux – Keyboard shortcut for toggle window (activate/minimize)

keyboardkeyboard shortcutslinuxUbuntuxdotools

Based on this answer I can activate or minimalize window:
how to bring up keepassX window with keyboard shortcut?

xdotool search --onlyvisible --name "My window name" windowactivate
xdotool search --onlyvisible --name "My window name" windowminimize

I assign these commands to two keyboard shortcuts, for example Ctrl+Shift+K and Ctrl+Shift+M.

But I want to have only one keyboard shortcut for toggle window, it means:

if minimalized:
   activate 
else:
   minimalize

I don't see any "toggle" option in xdotool:
http://manpages.ubuntu.com/manpages/trusty/man1/xdotool.1.html

OS: Ubuntu, UI: Unity

Best Answer

I often use xdotool with xprop and xev. They both give you a lot of window information.
You could write a simple script that gets information about the window with xprop or xev and implements the if-else block you've written. This is perhaps the most versatile solution, suitable not just for the task you're describing but for all things window management.

Another great tool for tinkering with your window manager is wmctrl. It believe does what you want without scripting:
wmctrl -r "My window name (or id)" -b toggle,hidden

The man page is pretty terse, I found this wmctrl user documentation more elucidating.

Mind that a lot depends on the window manager you use. These tools are EWMH comatible but it can differ a lot how windows are iconified, hidden, sticked, moved to other desktops etc.

Related Question