I want to run terminal or focus it by pressing F1 button. What I've tried to implement it:

  1. Add custom shortcut to gnome keyboard settings with such command.

    wmctrl -s 4 && pgrep terminator || nohup terminator > /dev/null &`
    • wmctrl -s 4 switches screen,
    • then pgrep terminator checks if terminal already running,
    • nohup terminator > /dev/null & runs terminal if it is not.

    The screen switches right, but terminal not opens.

  2. Place the command (as above) to executable *.sh file and specify absolute path to it in shortcut settings.
    All the same.

  3. Run above command in another terminal.
    Works as expected. (screen switches, terminator opens)

  4. Run script with above command:

    wmctrl -s 4 && pgrep terminator || nohup terminator > /dev/null &

    Not works again. Screen switches but terminator window not appears. Also there is pid number in the terminal after running the script.

It seems like the terminator closes after lunching for some reason.

What I should do to create shortcut with such actions?

  • Note that (assuming you're using gnome terminator) pgrep terminator always fails. Try pgrep -f terminator || nohup terminator instead. That's because terminator is a python program so what you see in pgrep is python, not terminator.
    – terdon
    Jan 14, 2017 at 18:04
  • Thank you for your clarification. But in my case pgrep terminator works as expected. It returns pid of running terminator instance. Jan 14, 2017 at 18:07
  • That's strange then. I would try i) redirecting the error output of the script to a file to see if anything is printed; ii) trying to run terminator without the nohup and without the wmctrl, to see which part of the command is the problem.
    – terdon
    Jan 14, 2017 at 18:11

1 Answer 1


I solved the problem by adding -x flag to pgrep. When I run my script named terminator.sh, pgrep always returns true and the last part of the command never executes. This is correct command:

wmctrl -s 4 && pgrep -x terminator || nohup terminator > /dev/null &

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .