Friday, May 17, 2024
3
rated 0 times [  3] [ 0]  / answers: 1 / hits: 405  / 2 Years ago, wed, february 23, 2022, 8:14:00

Ctrl + Alt + T opens a new terminal window. How do I make a keyboard shortcut open an existing window for an application if one is already open (and open a new one if not)?


More From » shortcut-keys

 Answers
6

The basic way to run-or-raise an application, i.e., switch to it if it is running, else run it, is a one-line terminal command. It uses wmctrl. Install it with sudo apt install wmctrl. Then enter the following command for your shortcut key:


sh -c "wmctrl -x -a Gnome-terminal || gnome-terminal"

wmctrl checks if a window with class Gnome-terminal exists. If that fail (||) the second command is executed, which is just launching a new instance of gnome-terminal. sh -c is needed to wrap it all in a single command.


You can find the window class of an open window by running xprop | grep WM_CLASS in a terminal, then clicking on the window.


You can delete the default Ctrl+Alt+t keybinding and replace it by your own custom version.


An option on steroids that I use is a script jumpapp. The GitHub page explains how to install it in Ubuntu as a .deb package, so it is registered in the package management system. The command for your shortcut key becomes as simple as:


jumpapp gnome-terminal

The added value over the basic way is that jumpapp will allow you to cycle through multiple open windows when you repeatedly hit the shortcut key, and can accomodate some specific cases. Read all about it in the excellent man page, man jumpapp.


[#1750] Thursday, February 24, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
itutejagua

Total Points: 89
Total Questions: 124
Total Answers: 113

Location: British Indian Ocean Territory
Member since Sun, Feb 13, 2022
2 Years ago
itutejagua questions
;