manjaro: how to set a keyboard shortcut that switches to a program, or starts if it isn't running

1.6k Views Asked by At

For instance the terminal shortcut ctrl+shift+T opens a new terminal - regardless of whether or not there's already a running instance.

How can I make it so that ctrl+shift+T works as follows:

if there is instance of terminal
   switch to it
else
   open new instance
1

There are 1 best solutions below

0
On

You could do it this way:

Install "wm_ctrl" first, then create a script file with the following contents:

#!/bin/bash

    if [ "$(ps -C $1| grep $1 | awk '{print $1}')" = "" ]; then
        $1
        else
            wmctrl -ia "$(wmctrl -lp | grep "$(pgrep "$1")" | tail -1 | awk '{ print $1 }')"
    fi

If you save the file as e.g. "try.sh", execute it with:

./try.sh firefox

if you want to test it with Firefox.