Terminator: single window, focus on launch
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?
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
.
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
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
- Change Terminator shortcut command in
Main Menu
to point to the above script - 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!