1

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.

  • 1
    Did you look under /org/gnome/terminal/legacy/profiles:/ in dconf? – FedKad Feb 27 '23 at 09:09
  • @FedKad I've added more information to my question in response to your comment. – John Smith Feb 27 '23 at 09:16
  • 1
    I am not talking about any /org directory. I am talking about the dconf key path. Please, try dconf dump /org/gnome/terminal/legacy/profiles:/ – FedKad Feb 27 '23 at 09:18

2 Answers2

2

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
  • 10,515
  • dconf dump /org/gnome/terminal/legacy/profiles:/ gave me this [:b1dcc9dd-5262-4d8d-a863-c897e6d979b9] background-color='rgb(255,255,255)' font='Monospace 21' foreground-color='rgb(0,0,0)' use-system-font=false use-theme-colors=false This Unnamed profile is not a profile that I created, it is on every Ubuntu Desktop installation. b1dcc9dd-5262-4d8d-a863-c897e6d979b9 seems to be its id. I figured out how to do this manually from dconf-editor but I need a solution that is non-interactive and can be run as a script via cron. – John Smith Feb 27 '23 at 10:00
  • 1
    Use the dconf write key_path new_value command in a script. Please, note that these values are per user, so your cron script should be run from the current user. – FedKad Feb 27 '23 at 10:12
1

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.