Ubuntu – Command-line to switch between profiles in gnome-terminal

command linegnome-terminalshortcut-keys

I created a new profile for gnome-terminal and I can switch between "Implicit" profile and the new created profile as you can see in the below image:

Switch between profiles in gnome-terminal

Now I wonder how can I switch between profiles using a command-line/script or maybe using a shortcut for this.

Note: Solutions like:

gnome-terminal --tab-with-profile=Implicit && exit 

are excluded because I prefer not to close and open another terminal or get another terminal window in this process of changing the profile.

Best Answer

A lot of great answers already but I wanted to add one more variation using xdotool that does not require the menu bar to be visible...

The key combo shift+F10 will open a pop-up menu (the equivalent of right-clicking on terminal) and from there the profile can be changed.

e.g. xdotool key shift+F10 r 3 to get to the third profile

I've also found that this method does not require setting a delay for xdotool (which I found necessary for the menu bar method) so it's therefore a little faster.

I tend to change profiles a lot so I wrap this into a function:

function chp(){
      xdotool key --clearmodifiers Shift+F10 r $1

so I can just call chp N to switch to the Nth profile.

Some more tips and idiosyncrasies of my setup:

  • By adding a chp command to my .bashrc I can force new tabs to always switch to the default profile

  • I color code my ssh sessions based on host but I don't like my ssh alias to open new tabs or windows AND I want the profile to change back to the default when I exit ssh. My solution: alias somehost="chp 2; ssh user@somehost; chp 1"

  • I give xdotool the flag --clearmodifiers so that if I happen to be holding a modifier key (when opening a tab/window, exiting ssh, etc.), it won't interfere with xdotool.

  • I prepend my profile names with numbers so that if I add a new one, it doesn't shift all the others due to the alphabetizing of the profile menu