Focus existing terminal with `Ctrl-Alt-T` shortcut












16














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?










share|improve this question





























    16














    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?










    share|improve this question



























      16












      16








      16


      6





      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?










      share|improve this question















      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?







      command-line gnome-terminal window






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Oct 17 '12 at 15:40









      Peyman Mahdian

      208210




      208210










      asked Oct 14 '12 at 11:04









      Hailwood

      2,277133770




      2,277133770






















          5 Answers
          5






          active

          oldest

          votes


















          24














          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/nulln 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.






          share|improve this answer























          • You could add a | head -n1 after searching gnome-terminal windows to prevent an error if more than one windows are found
            – ggalmazor
            May 12 '17 at 7:17



















          8














          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






          share|improve this answer































            1














            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





            share|improve this answer































              0














              try



              sudo apt-get install wmctrl
              wmctrl -xa 'gnome-terminal-server.Gnome-terminal'


              go to system settings - Keyborad, add a custom shortcut, and paste the wmctrl command there. It works.



              where the gnome-terminal-* string is from



              wmctrl -xl





              share|improve this answer





























                0














                Yet another option: launch or switch. The script relies on wmctrl to check whether a window is already open. If it is, the script switches to an existing one, giving priority to an existing window on the current desktop. Otherwise, a new window is lauched. This script is published by Vaughn Dickson.



                #!/bin/sh

                terminal_wm_class="gnome-terminal"
                terminal_exec="gnome-terminal"

                # no terminal started, so start one
                if [ -z "`wmctrl -lx | grep gnome-terminal`" ]; then
                $terminal_exec &
                else
                # search for existing terminals on current desktop
                current_desk=`wmctrl -d | grep '*' | cut -d ' ' -f 1`
                term_on_this_desk=`wmctrl -lx | grep "$current_desk[ ]*$terminal_wm_class" | cut -d ' ' -f 1`
                if [ -n "$term_on_this_desk" ]; then
                wmctrl -i -a $term_on_this_desk
                else
                # no terminals on current desktop, so just open the first one we find
                wmctrl -x -a $terminal_wm_class
                fi;
                fi;


                Place this script in the bin folder in your home folder and make it executable. Then under Keyboard Shortcuts (Settings - Keyboard), disable the existing hotkey for "Launch terminal" under the section "Launchers": click on it, then press Backspace to disable the current assignment. Then, in the section "Custom Shortcuts", create a new custom shortcut by clicking the + icon. Fill out the name of your script as the "command" and assign it the Ctrl+Alt+t shortcut.






                share|improve this answer























                  Your Answer








                  StackExchange.ready(function() {
                  var channelOptions = {
                  tags: "".split(" "),
                  id: "89"
                  };
                  initTagRenderer("".split(" "), "".split(" "), channelOptions);

                  StackExchange.using("externalEditor", function() {
                  // Have to fire editor after snippets, if snippets enabled
                  if (StackExchange.settings.snippets.snippetsEnabled) {
                  StackExchange.using("snippets", function() {
                  createEditor();
                  });
                  }
                  else {
                  createEditor();
                  }
                  });

                  function createEditor() {
                  StackExchange.prepareEditor({
                  heartbeatType: 'answer',
                  autoActivateHeartbeat: false,
                  convertImagesToLinks: true,
                  noModals: true,
                  showLowRepImageUploadWarning: true,
                  reputationToPostImages: 10,
                  bindNavPrevention: true,
                  postfix: "",
                  imageUploader: {
                  brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
                  contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
                  allowUrls: true
                  },
                  onDemand: true,
                  discardSelector: ".discard-answer"
                  ,immediatelyShowMarkdownHelp:true
                  });


                  }
                  });














                  draft saved

                  draft discarded


















                  StackExchange.ready(
                  function () {
                  StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f200929%2ffocus-existing-terminal-with-ctrl-alt-t-shortcut%23new-answer', 'question_page');
                  }
                  );

                  Post as a guest















                  Required, but never shown

























                  5 Answers
                  5






                  active

                  oldest

                  votes








                  5 Answers
                  5






                  active

                  oldest

                  votes









                  active

                  oldest

                  votes






                  active

                  oldest

                  votes









                  24














                  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/nulln 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.






                  share|improve this answer























                  • You could add a | head -n1 after searching gnome-terminal windows to prevent an error if more than one windows are found
                    – ggalmazor
                    May 12 '17 at 7:17
















                  24














                  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/nulln 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.






                  share|improve this answer























                  • You could add a | head -n1 after searching gnome-terminal windows to prevent an error if more than one windows are found
                    – ggalmazor
                    May 12 '17 at 7:17














                  24












                  24








                  24






                  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/nulln 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.






                  share|improve this answer














                  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/nulln 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.







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited May 23 '17 at 12:39









                  Community

                  1




                  1










                  answered Oct 14 '12 at 11:26









                  zerwas

                  3,32311618




                  3,32311618












                  • You could add a | head -n1 after searching gnome-terminal windows to prevent an error if more than one windows are found
                    – ggalmazor
                    May 12 '17 at 7:17


















                  • You could add a | head -n1 after searching gnome-terminal windows to prevent an error if more than one windows are found
                    – ggalmazor
                    May 12 '17 at 7:17
















                  You could add a | head -n1 after searching gnome-terminal windows to prevent an error if more than one windows are found
                  – ggalmazor
                  May 12 '17 at 7:17




                  You could add a | head -n1 after searching gnome-terminal windows to prevent an error if more than one windows are found
                  – ggalmazor
                  May 12 '17 at 7:17













                  8














                  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






                  share|improve this answer




























                    8














                    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






                    share|improve this answer


























                      8












                      8








                      8






                      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






                      share|improve this answer














                      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







                      share|improve this answer














                      share|improve this answer



                      share|improve this answer








                      edited Oct 14 '12 at 14:17

























                      answered Oct 14 '12 at 11:09









                      bartekbrak

                      2,28511120




                      2,28511120























                          1














                          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





                          share|improve this answer




























                            1














                            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





                            share|improve this answer


























                              1












                              1








                              1






                              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





                              share|improve this answer














                              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






                              share|improve this answer














                              share|improve this answer



                              share|improve this answer








                              edited Aug 7 at 6:31

























                              answered Oct 18 '15 at 17:58









                              Possum Gallo

                              213




                              213























                                  0














                                  try



                                  sudo apt-get install wmctrl
                                  wmctrl -xa 'gnome-terminal-server.Gnome-terminal'


                                  go to system settings - Keyborad, add a custom shortcut, and paste the wmctrl command there. It works.



                                  where the gnome-terminal-* string is from



                                  wmctrl -xl





                                  share|improve this answer


























                                    0














                                    try



                                    sudo apt-get install wmctrl
                                    wmctrl -xa 'gnome-terminal-server.Gnome-terminal'


                                    go to system settings - Keyborad, add a custom shortcut, and paste the wmctrl command there. It works.



                                    where the gnome-terminal-* string is from



                                    wmctrl -xl





                                    share|improve this answer
























                                      0












                                      0








                                      0






                                      try



                                      sudo apt-get install wmctrl
                                      wmctrl -xa 'gnome-terminal-server.Gnome-terminal'


                                      go to system settings - Keyborad, add a custom shortcut, and paste the wmctrl command there. It works.



                                      where the gnome-terminal-* string is from



                                      wmctrl -xl





                                      share|improve this answer












                                      try



                                      sudo apt-get install wmctrl
                                      wmctrl -xa 'gnome-terminal-server.Gnome-terminal'


                                      go to system settings - Keyborad, add a custom shortcut, and paste the wmctrl command there. It works.



                                      where the gnome-terminal-* string is from



                                      wmctrl -xl






                                      share|improve this answer












                                      share|improve this answer



                                      share|improve this answer










                                      answered Oct 11 at 3:09









                                      Jake

                                      101




                                      101























                                          0














                                          Yet another option: launch or switch. The script relies on wmctrl to check whether a window is already open. If it is, the script switches to an existing one, giving priority to an existing window on the current desktop. Otherwise, a new window is lauched. This script is published by Vaughn Dickson.



                                          #!/bin/sh

                                          terminal_wm_class="gnome-terminal"
                                          terminal_exec="gnome-terminal"

                                          # no terminal started, so start one
                                          if [ -z "`wmctrl -lx | grep gnome-terminal`" ]; then
                                          $terminal_exec &
                                          else
                                          # search for existing terminals on current desktop
                                          current_desk=`wmctrl -d | grep '*' | cut -d ' ' -f 1`
                                          term_on_this_desk=`wmctrl -lx | grep "$current_desk[ ]*$terminal_wm_class" | cut -d ' ' -f 1`
                                          if [ -n "$term_on_this_desk" ]; then
                                          wmctrl -i -a $term_on_this_desk
                                          else
                                          # no terminals on current desktop, so just open the first one we find
                                          wmctrl -x -a $terminal_wm_class
                                          fi;
                                          fi;


                                          Place this script in the bin folder in your home folder and make it executable. Then under Keyboard Shortcuts (Settings - Keyboard), disable the existing hotkey for "Launch terminal" under the section "Launchers": click on it, then press Backspace to disable the current assignment. Then, in the section "Custom Shortcuts", create a new custom shortcut by clicking the + icon. Fill out the name of your script as the "command" and assign it the Ctrl+Alt+t shortcut.






                                          share|improve this answer




























                                            0














                                            Yet another option: launch or switch. The script relies on wmctrl to check whether a window is already open. If it is, the script switches to an existing one, giving priority to an existing window on the current desktop. Otherwise, a new window is lauched. This script is published by Vaughn Dickson.



                                            #!/bin/sh

                                            terminal_wm_class="gnome-terminal"
                                            terminal_exec="gnome-terminal"

                                            # no terminal started, so start one
                                            if [ -z "`wmctrl -lx | grep gnome-terminal`" ]; then
                                            $terminal_exec &
                                            else
                                            # search for existing terminals on current desktop
                                            current_desk=`wmctrl -d | grep '*' | cut -d ' ' -f 1`
                                            term_on_this_desk=`wmctrl -lx | grep "$current_desk[ ]*$terminal_wm_class" | cut -d ' ' -f 1`
                                            if [ -n "$term_on_this_desk" ]; then
                                            wmctrl -i -a $term_on_this_desk
                                            else
                                            # no terminals on current desktop, so just open the first one we find
                                            wmctrl -x -a $terminal_wm_class
                                            fi;
                                            fi;


                                            Place this script in the bin folder in your home folder and make it executable. Then under Keyboard Shortcuts (Settings - Keyboard), disable the existing hotkey for "Launch terminal" under the section "Launchers": click on it, then press Backspace to disable the current assignment. Then, in the section "Custom Shortcuts", create a new custom shortcut by clicking the + icon. Fill out the name of your script as the "command" and assign it the Ctrl+Alt+t shortcut.






                                            share|improve this answer


























                                              0












                                              0








                                              0






                                              Yet another option: launch or switch. The script relies on wmctrl to check whether a window is already open. If it is, the script switches to an existing one, giving priority to an existing window on the current desktop. Otherwise, a new window is lauched. This script is published by Vaughn Dickson.



                                              #!/bin/sh

                                              terminal_wm_class="gnome-terminal"
                                              terminal_exec="gnome-terminal"

                                              # no terminal started, so start one
                                              if [ -z "`wmctrl -lx | grep gnome-terminal`" ]; then
                                              $terminal_exec &
                                              else
                                              # search for existing terminals on current desktop
                                              current_desk=`wmctrl -d | grep '*' | cut -d ' ' -f 1`
                                              term_on_this_desk=`wmctrl -lx | grep "$current_desk[ ]*$terminal_wm_class" | cut -d ' ' -f 1`
                                              if [ -n "$term_on_this_desk" ]; then
                                              wmctrl -i -a $term_on_this_desk
                                              else
                                              # no terminals on current desktop, so just open the first one we find
                                              wmctrl -x -a $terminal_wm_class
                                              fi;
                                              fi;


                                              Place this script in the bin folder in your home folder and make it executable. Then under Keyboard Shortcuts (Settings - Keyboard), disable the existing hotkey for "Launch terminal" under the section "Launchers": click on it, then press Backspace to disable the current assignment. Then, in the section "Custom Shortcuts", create a new custom shortcut by clicking the + icon. Fill out the name of your script as the "command" and assign it the Ctrl+Alt+t shortcut.






                                              share|improve this answer














                                              Yet another option: launch or switch. The script relies on wmctrl to check whether a window is already open. If it is, the script switches to an existing one, giving priority to an existing window on the current desktop. Otherwise, a new window is lauched. This script is published by Vaughn Dickson.



                                              #!/bin/sh

                                              terminal_wm_class="gnome-terminal"
                                              terminal_exec="gnome-terminal"

                                              # no terminal started, so start one
                                              if [ -z "`wmctrl -lx | grep gnome-terminal`" ]; then
                                              $terminal_exec &
                                              else
                                              # search for existing terminals on current desktop
                                              current_desk=`wmctrl -d | grep '*' | cut -d ' ' -f 1`
                                              term_on_this_desk=`wmctrl -lx | grep "$current_desk[ ]*$terminal_wm_class" | cut -d ' ' -f 1`
                                              if [ -n "$term_on_this_desk" ]; then
                                              wmctrl -i -a $term_on_this_desk
                                              else
                                              # no terminals on current desktop, so just open the first one we find
                                              wmctrl -x -a $terminal_wm_class
                                              fi;
                                              fi;


                                              Place this script in the bin folder in your home folder and make it executable. Then under Keyboard Shortcuts (Settings - Keyboard), disable the existing hotkey for "Launch terminal" under the section "Launchers": click on it, then press Backspace to disable the current assignment. Then, in the section "Custom Shortcuts", create a new custom shortcut by clicking the + icon. Fill out the name of your script as the "command" and assign it the Ctrl+Alt+t shortcut.







                                              share|improve this answer














                                              share|improve this answer



                                              share|improve this answer








                                              edited 2 days ago

























                                              answered 2 days ago









                                              vanadium

                                              4,82911228




                                              4,82911228






























                                                  draft saved

                                                  draft discarded




















































                                                  Thanks for contributing an answer to Ask Ubuntu!


                                                  • Please be sure to answer the question. Provide details and share your research!

                                                  But avoid



                                                  • Asking for help, clarification, or responding to other answers.

                                                  • Making statements based on opinion; back them up with references or personal experience.


                                                  To learn more, see our tips on writing great answers.





                                                  Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                                                  Please pay close attention to the following guidance:


                                                  • Please be sure to answer the question. Provide details and share your research!

                                                  But avoid



                                                  • Asking for help, clarification, or responding to other answers.

                                                  • Making statements based on opinion; back them up with references or personal experience.


                                                  To learn more, see our tips on writing great answers.




                                                  draft saved


                                                  draft discarded














                                                  StackExchange.ready(
                                                  function () {
                                                  StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f200929%2ffocus-existing-terminal-with-ctrl-alt-t-shortcut%23new-answer', 'question_page');
                                                  }
                                                  );

                                                  Post as a guest















                                                  Required, but never shown





















































                                                  Required, but never shown














                                                  Required, but never shown












                                                  Required, but never shown







                                                  Required, but never shown

































                                                  Required, but never shown














                                                  Required, but never shown












                                                  Required, but never shown







                                                  Required, but never shown







                                                  Popular posts from this blog

                                                  Human spaceflight

                                                  Can not write log (Is /dev/pts mounted?) - openpty in Ubuntu-on-Windows?

                                                  張江高科駅