Ubuntu – Focus or open window in gnome on keyboard shortcut


As described here (askubuntu.com/questions/234206/shortcut-to-switch-to-app/328842) the wmctrl gives you access to your windows. So you can switch via keyboard. But I like to have one shortcut to open and focus if it is yet open.

Is there a tool for that?

Best Answer

Yet another solution.

Make sure you have wmctrl installed: sudo apt install wmctrl

Make a shortcut with the command: bash -c "wmctrl -a chrome ; [ "$?" == "1" ] && google-chrome"

Explanation: first we try to focus on chrome (wmctrl -vxa chrome), next we verify if we are successful "$?" == "0" or not "$?" == "1" and if not we then launch google chrome ([ "$?" == "1" ] && google-chrome").

You also could make the shortcut bash -c "wmctrl -a chrome || google-chrome"

|| means that if the first command fails, execute the second.