Saturday, May 4, 2024
4
rated 0 times [  4] [ 0]  / answers: 1 / hits: 583  / 2 Years ago, wed, may 25, 2022, 3:53:25

I have a habit of hitting Ctrl+Alt+T to show my terminal when using Ubuntu (GNOME). After a while I have a plethora of terminal windows open, when all I really need is one.


How can I make Ctrl+Alt+T not necessarily open a new terminal window, but show the one I have already opened?


The logic should be like this: If a terminal is already opened, show it. If no terminal is open, open a new terminal (equal to default behaviour).


More From » command-line

 Answers
5

Save this as a script, but change all occurrences of xfce4-terminal with your regular terminal name:


#!/bin/bash

if [[ $(pgrep -x xfce4-terminal) ]]; then xdotool windowactivate `xdotool search --pid $(pgrep -x xfce4-terminal) | tail -1`; else xfce4-terminal; fi

And add a shortcut that executes that script. This might differ depending on your OS.


On Xubuntu you can enter the path to the script into Keyboard/Application Shortcuts.


You might need to install xdotool if you haven't already:


sudo apt install xdotool

In my tests this opened the terminal in which you executed the last command.


[#594] Thursday, May 26, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
barted

Total Points: 424
Total Questions: 103
Total Answers: 101

Location: Djibouti
Member since Sun, Feb 27, 2022
2 Years ago
barted questions
;