0

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:/
:7e95bbb3-a584-469d-8ae1-75a08287f55a/
:b79f95fc-b8a9-40b8-beca-5a1c1aee078a/
:833171c4-5fa6-4038-af36-e667ab2d876b/
:611439c9-b5cb-4b3f-9166-50897a705e29/
:5e0814a6-5f24-4823-9f54-d4accb9d9d92/
:403d9eb7-16d5-46be-864f-42d9651dda49/
:7bad96ca-3efc-40d0-9a8d-9e0c5d67738e/
:b0ac22f9-3c3a-42b5-ab5d-542d8465f2a0/
list
:4f99e9d3-caa3-4e88-8bc5-a1b6efe0b1ff/
:efbf6322-e497-4918-88e1-b44167d306fc/
:cb2c2176-2a0e-4e8b-83a9-ff2d9c456cb9/
:5ec02300-aa59-4bda-b33c-0e992f8adefb/
:de0d4915-5db9-4d58-a24a-7b7054ccfae1/
:7c6e6069-0dfb-48a9-bc3b-b4b2f486061e/
:484cd255-71a8-4655-b0cf-98b3f2e58abb/
default
:3bfaf350-2cf3-4f87-8ef9-cdadfc5f46bf/
:9e62c391-a298-419a-a0a5-32ad8adf0015/
:cc854d98-9559-4eed-9014-8e622bb8dbcb/
:e6f55cc9-a78e-4727-91f3-0d0623c258ea/
:b358abc2-c1ba-4968-9da9-95e3becf2cda/
:8e8a102d-ac00-47ff-a05c-dc2208b6643e/
:7b44f31c-f78e-4308-87e6-87a77279c2b6/
:893a4288-62ab-4431-bca6-68b5928aa7d9/
:2433ec9b-ab41-4f90-9268-36fd5b3c8c9c/
:34e6a4c0-72ee-4f11-820a-f3b8fdeb6b05/
:03707c06-6c4e-46db-acf0-d97ff2d791fe/
:a6716d99-075e-4001-8030-919ee772b3c6/
:009bf635-944a-4de6-8b6f-52ccc190b2e9/
:d11a727f-bd8e-4b35-91c3-beaadf4fd445/
:ce9edba1-cf35-4d4a-9a2f-6423af523c1a/

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'
1
  • Voting to close as duplicate of this since it sounds like no better answers exist
    – lucidbrot
    Sep 9 '20 at 11:54
0

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.