0

Example on hyper terminal:

I press alt+h, the script should check if hyper is already running in the background.

If yes, it should open already the opened window.
If not, open a new window.

OS: Ubuntu 18.04

1

For creating the keyboard shortcut, it depends upon your DesktopManager. In Ubuntu 18 this answer explains how. Below is the command you should set to be launched by you shortcut.

This simple commands does the job of switching to the Hyper window for my Window Manager:

wmctrl -a Hyper

All Window/Desktop Managers which supports EWMH/NetWM specification can use wmctrl. Most probably the Ubuntu desktop is compatible, but you probably need to install wmctrl.

I leave my previous answer, just to let you dabble with other things possible to do with your desktop. This is the way I found the command just above.


OLD ANSWER:

Some key elements about the script you could try to write:

  1. ps -xau | grep hyper would get the info whether the process is already running or not. Beware that there will also be listed the grep process that was searching for hyper .

  2. Step 1 is maybe optional. Most probably your Window Manager supports the EWMH/NetWM specification. As a consequence you can use wmctrl. You probably have to install it. Type wmctrl in a terminal to see if it is there.

  3. wmctrl -l will give you a list of all currently opened window.

  4. You can then activate the desired window and go to that window with either wmctrl -a or wmctrl -R

wmctrl -h will tell you the different other operation that you can do with your desktop.

e.g. on my machine (with several opened windows and desktops), after launching Hyper, when typing wmctrl -l I have:

0x02c00006 18 mymachine urxvt
0x02e00006 19 mymachine ncurses.h = (/nix/store/ffjl7aw7f0gjwv4gb4mgb0w49v5dhrkg-ncurses-6.0-20171125-dev/include) - VIM
0x03c00006 16 mymachine urxvt
0x03000006 20 mymachine urxvt
0x03a00006  8 mymachine urxvt
0x00e00006 24 mymachine urxvt
0x01800003 15 mymachine Volume Control
0x04c00005  1 mymachine Hyper
0x03e00001 15 mymachine 2.3. Using Precedences - Chromium
0x03e00006 15 mymachine Edit - Unix & Linux Stack Exchange - Chromium
0x03e00007 15 mymachine C++ Core Guidelines - Chromium

notice the line: it says on desktop 1, there's the window 0x04c00005 which has the name Hyper:

0x04c00005  1 mymachine Hyper

you can get this line directly using command:

wmctrl -l | grep Hyper

so as to activate the window:

wmctrl -a 0x04c00005

However for some reason I don't know why this latest command doesn't work in my Fluxbox environment... It is possbile that Fluxbox doesn't implement every wmctrl functionnalities.

You should test it. If that works in your Ubuntu environement, try to write the bash script that automates those different commands. Then tell us what you succeed in or block on.

EDIT: It seems the wmctrl -a expect the Title of the window, not the hexadecimal ID.

So the solution is simply:

wmctrl -a Hyper   

you could aslo try

wmctrl -R Hyper
1

The key is to find a unique name for Hyper in the window title bar that would not correspond to a key word of any other programs open. I do not have the program you refer to installed, but I tested mine on Debian 9 with Xfce and mousepad. So you could add this as your keyboard shortcut:

bash -c 'wmctrl -a Mousepad || mousepad'

Just replace Mousepad with a key word from the window title bar, and on the second part use the program name you would use to execute it from the terminal. The above command activates the window if it is open already. However, if the command fails, i.e. || then it launches the program.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.