Sunday, April 28, 2024
28
rated 0 times [  28] [ 0]  / answers: 1 / hits: 4763  / 3 Years ago, fri, november 5, 2021, 8:09:15

I tend to use the terminal a lot,



So I wondering if there is a way I can make Ctrl+Alt+T focus the existing terminal if there is one, otherwise create a new terminal?


More From » command-line

 Answers
3

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
then xdotool windowactivate $(xdotool search --onlyvisible --class gnome-terminal)
else gnome-terminal &
fi' > ~/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.


[#34970] Sunday, November 7, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ersoggles

Total Points: 69
Total Questions: 111
Total Answers: 111

Location: Vanuatu
Member since Sun, Oct 2, 2022
2 Years ago
;