How to change "Global Dark Theme" on and off through Terminal?

I know how to set and display most themes, however I can find anything about how to turn the Global Dark Theme on and off through Terminal, I can only find the option in the gnome-tweak-tool. So is there not a way to turn it on and off through Terminal? I am running Ubuntu GNOME 15.10 with GNOME 3.18.


Solution 1:

To set the global dark theme from the command line, first navigate to a Terminal of your choice and then from within the shell emulator ...

Navigate to your home directory:

 cd ~

Create a new file called settings.ini inside of the GTK 4 directory:

 nano ~/.config/gtk-4.0/settings.ini

Enter the following fields into the configuration file:

[Settings]
gtk-application-prefer-dark-theme=1

Write the changes to disk by pressing control + x, then press y, then enter.

Solution 2:

For modern Gnome desktops:

  • Tested: Ubuntu 18.04, 20.04; Fedora 27, 32 enter image description here

Default dark mode:

gsettings set org.gnome.desktop.interface gtk-theme 'Adwaita-dark'

Default light mode:

gsettings set org.gnome.desktop.interface gtk-theme 'Adwaita'

Getting a list of available base theme names:

ls -d /usr/share/themes/* |xargs -L 1 basename

Caveats:

  • Some existing limitations to changing the theme: https://bugzilla.gnome.org/show_bug.cgi?id=783666 (bug conversation mentions them)

  • It appears that there's some variance in how this is adopted with Adwaita being the currently accepted default, but the tweak tool will also attempt to write to the settings.ini files.

  • Furthemore, applications provided as snaps may ship with their own settings.ini files making a command line solution much more difficult than a one-liner.

Ideally, a technique to invoke gnome-tweak-tool through CLI would cover most scenarios holistically. Gnome-tweak-tool is written in python3, so this should be theoretically possible to someone familiar with Python.