Focus existing terminal with `Ctrl-Alt-T` shortcut
Create a small script which will raise the GNOME Terminal:
echo 'xdotool windowactivate $(xdotool search --onlyvisible --class gnome-terminal)'> ~/raiseterminal.sh && chmod +x ~/raiseterminal.sh
or if you want to check if Terminal is already running, use:
echo -e $'if ps aux | grep "[g]nome-terminal" > /dev/null\n then xdotool windowactivate $(xdotool search --onlyvisible --class gnome-terminal)\n else gnome-terminal &\nfi' > ~/raiseterminal.sh && chmod +x ~/raiseterminal.sh
This will create the script ~/raiseterminal.sh with this content:
if ps aux | grep "[g]nome-terminal" > /dev/null
then xdotool windowactivate $(xdotool search --onlyvisible --class gnome-terminal)
else gnome-terminal&
fi
Open the preferences to set up a custom keyboard shortcut and set the command to /home/$USER/raiseterminal.sh
, but make sure to change $USER to your actual username.
If you only want to raise the terminal on a specific screen or desktop, see xdotool search --help
for more information on how to do this.
There are also various other methods which work better with other window managers.
why don't you try tilda
or guake
, both available in ubuntu repositories. Although they don't specifically do what you're after, I'm sure they are that thing that you were looking for but did not know it existed. ;)
EDIT: ok, I was a bit vague, more information follows:
from wikipedia:
Tilda is a GTK+ terminal emulator. Its design was inspired from consoles in computer games such as Quake which slide down from the top of the screen when a key is pressed, typically the tilde, and slide back up when the key is pressed again.
Running Tilda can be faster than launching a new terminal with a keyboard shortcut because the program is already loaded into memory; it can be useful to people who frequently find themselves opening and closing terminals for odd tasks.
guake
is really the same thing, the only difference I noticed is that I couldn't make it open http links by ctrl+click which I found annoying
My version (=
Script to run/raise any app:
PID=$$
xdotool search --class $1 | while read line
do
echo "$line"
if [ `xdotool windowactivate $line 2> /dev/stdout | grep -c fail` -eq 0 ]
then
kill $PID
exit
fi
done
## Launch the program if we reach here
$1 & disown
e.g.
sh ~/raise.sh chromium