I have set up several color profiles (e.g. some from here) whose UUIDs I can now list with

$ dconf list /org/gnome/terminal/legacy/profiles:/

I would like to set each new terminal window to any (random or round-robin) profile. This, I assume, I could do with a command in ~/.bashrc. For that, I require one piece of knowledge:

How can I change the currently active profile from the command line?

I know I could manually set it with right click > Profiles > myprofile. I also know I can start a new terminal window with the desired profile using

$ gnome-terminal --profile='7e95bbb3-a584-469d-8ae1-75a08287f55a'
  • Voting to close as duplicate of this since it sounds like no better answers exist
    – lucidbrot
    Sep 9 '20 at 11:54

This answer works but introduces bugs. But here is a better solution

# install
sudo apt install xdotool
# activate third profile
xdotool key --clearmodifiers Shift+F10 r 3

This simulates the keypresses of opening the profile selection menu and choosing an entry. The options to choose numerate from 1 to 9 and then from A to Z.

I'm not entirely happy with this solution because it seems like there should be a way to do this that is more builtin (less hacky) to the gnome terminal.

Source is this other answer I just found.

Here's the explanation for why we use --clearmodifiers:

Any command taking the --clearmodifiers flag will attempt to clear any active input modifiers during the command and restore them afterwards.

For example, if you were to run this command: xdotool key a

The result would be 'a' or 'A' depending on whether or not you were holding the shift key on your keyboard. Often it is undesirable to have any modifiers active, so you can tell xdotool to clear any active modifiers. man page

This means for a random color each time the terminal is opened, you can add to ~/.bashrc

# random color profile
profiles=('0' '1' '2' '3' '4' '5' '6' '7' '8' '9' 'a' 'b' 'c' 'd' 'e' 'f' 'g' 'h' 'i' 'j' 'k' 'l' 'm' 'n' 'u' 'v')
random=$$$(date +%s)
xdotool key --clearmodifiers Shift+F10 r ${profiles[$random % ${#profiles[@]}]}

This causes slight lag before the color change though, which is noticeable. It also causes the complete OS to become unusable at times - not even alt tab working anymore. I think that is related to this open issue

Not the answer you're looking for? Browse other questions tagged or ask your own question.