Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I am configuring Terminator for my desktop. I use the Ctrl + Alt + T shortcut to launch it. Since I want only a single instance running, I use run-one terminator as the launcher command.

Now if an Terminator instance is running, a new instance isn`t launched, but the existing instance does not get focused.

Any ideas as to how I could get the Terminator window to get focus?

share|improve this question
add comment

3 Answers

up vote 3 down vote accepted

Try to install wmctrl : sudo apt-get install wmctrl
now the command wmctrl -a STRING gives focus to a window containing STRING in its title
so your final command will be:

run-one terminator; wmctrl -a Terminator
share|improve this answer
    
Thanks for the pointer. I have found a solution which works pretty well, detailed below. –  Mr Hyde Dec 18 '11 at 18:27
add comment

Here is the hack I have settled upon using run-one and xdotool

In /home/(user)/my_scripts/single_terminator_instance.sh

#!/usr/bin/bash

# run a single instance of terminator
/usr/bin/run-one /usr/bin/terminator

# search for the terminator window and focus!!!
/usr/bin/xdotool search --onlyvisible --class terminator windowactivate

Then

  1. Change Terminator shortcut command in Main Menu to point to the above script
  2. In Keyboard shortcuts, Ctrl + Alt + T activates the script

While searching across the i'net, I also chanced upon this

Since I am new to bash scripts, I welcome any refinements to the hack!

share|improve this answer
    
Easier: /usr/bin/wmctrl -xa terminator :-) instead of xdotool! Thanks Denis. –  Mr Hyde Dec 18 '11 at 19:55
    
you are right! right way is wmctrl -xa terminator –  Denis Dec 23 '11 at 22:16
    
I tried your solutions, but run-one doesn't work on my computer with Terminator. It always launches a new instance. Do you have any idea why? Thanks. –  Barta Tamás Feb 22 at 19:38
    
ps aux | grep terminator returns nothing. The process runs as x-terminal-emulator for me, so that might be the cause. I did manual check like this: RUNNING=$(ps aux | grep x-terminal-emulator | grep -v grep) if [[ -z $RUNNING ]]; then x-terminal-emulator & fi –  Barta Tamás Feb 22 at 19:55
    
@BartaTamás Did you solve your problem. My script is just two lines of bash attached to keyboard shortcut. I now use it with gnome-terminal and tmux, and am very happy with the solution. But it also works reliably with terminator. Maybe the same keyboard shortcut is assigned twice (Ctrl+Alt+T). Just guessing! –  Mr Hyde Feb 22 at 21:57
add comment

Here is a method that works without run-one assuming wmctrl is available:

wmctrl -xa terminator.Terminator || terminator

This assumes the default window class name is being used. You can get creative if you want and use a custom class name when launching terminator. This will allow you to keep your terminator shortcut separate from a normal terminator instance:

wmctrl -xa MyCustomTerminator.Terminator || terminator -c MyCustomTerminator

This just builds on Denis' answer without the need for run-one.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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