2

How do I script changing from the light mode to the dark mode? In it GUI I do this: preferences>profiles>Unnamed>Colors>Bultin-in schemes (here I choose either black-on-white or white-on-black.

As far as I know, there is no config file. I use Ubuntu 22.04LTS Desktop and have no /org in my filesystem. How might I automate the process of changing the color scheme scripting the whole process with dconf or similar tools? The goal is to run the script via cron that changes from black-on-white to white-on-black at 2pm and vice versa at 7am.

I already know how to launch gnome-terminal with desired settings saved in a profile, e.g. gnome-terminal --profile=dark. This is not what I want to achieve because I want the already opened windows to change the color scheme.

2 Answers2

3

Please, use the command

dconf dump /org/gnome/terminal/legacy/profiles:/

and find the relevant "profile id" that has visible-name='Unnamed'.

Using the command dconf write key_path new_value, you can change the values of the following keys:

/org/gnome/terminal/legacy/profiles:/<profile_id>/background-color
/org/gnome/terminal/legacy/profiles:/<profile_id>/foreground-color

e.g. changing to dark theme:

dconf write /org/gnome/terminal/legacy/profiles:/:b1dcc9dd-5262-4d8d-a863-c897e6d979b9/background-color "'#000000'"
dconf write /org/gnome/terminal/legacy/profiles:/:b1dcc9dd-5262-4d8d-a863-c897e6d979b9/foreground-color "'#ffffff'"

where :b1dcc9dd-5262-4d8d-a863-c897e6d979b9 is your profile id.

FedKad
  • 13,420
2

I needed an interactive solution to deal with trendy tools that set the foreground color without checking the background color.

This function is part of my Bash profile. It allows me to switch between color schemes using the command colors light and colors dark.

function colors() {
    local black="'#000000'"
    local white="'#ffffff'"
    local background_color
    local foreground_color
    local default_profile="/org/gnome/terminal/legacy/profiles:/:b1dcc9dd-5262-4d8d-a863-c897e6d979b9"
case $@ in
    &quot;dark&quot;)
        background_color=&quot;$black&quot;
        foreground_color=&quot;$white&quot;
        ;;
    &quot;light&quot;)
        background_color=&quot;$white&quot;
        foreground_color=&quot;$black&quot;
        ;;
    *)
        echo &quot;Choose 'dark' or 'light'&quot; &gt;&amp;2
        return 1
        ;;
esac

dconf write &quot;$default_profile/background-color&quot; &quot;$background_color&quot;
dconf write &quot;$default_profile/foreground-color&quot; &quot;$foreground_color&quot;

}

vale and rain use dark grey or navy blue text in their help output which is impossible to read on a dark background.

With colors light, I can read the output of these tools:

Dark foreground color is visible on a white background.

With colors dark, the output of these tools is unreadable:

Dark foreground color is invisible on a black background.