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

37,589

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, 36 enter image description here

Default dark mode:

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

# Fedora 36 and above
gsettings set org.gnome.desktop.interface color-scheme 'prefer-dark'

Default light mode:

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

# Fedora 36 and above
gsettings set org.gnome.desktop.interface color-scheme 'default'

Getting a list of available base theme names:

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

Caveats:

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.

Fedora 36 introduced a new preference, color-scheme that is required to change theme for some apps (files, settings, software, …) and gtk-theme doesn’t work anymore for these apps.

Share:
37,589

Related videos on Youtube

Admin
Author by

Admin

Updated on September 18, 2022

Comments

  • Admin
    Admin over 1 year

    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.

  • Guilherme
    Guilherme about 5 years
    I did it, but didn't work...
  • oemb1905
    oemb1905 about 5 years
    Well, you need to leave way more information than that if you want help! @Guilherme
  • oemb1905
    oemb1905 about 5 years
    What distribution? Which release?
  • Guilherme
    Guilherme about 5 years
    I'm using the ubuntu 16.04.5 , I did it " nano ~/.config/gtk-3.0/settings.ini" and change to 1 and my nautilus didn't change
  • oemb1905
    oemb1905 about 5 years
    just nautilus, or everything else too? what about installing caja ... @Guilherme
  • Guilherme
    Guilherme about 5 years
    nothing are working... @oemb1905
  • oemb1905
    oemb1905 about 5 years
    Hmm ... maybe check the default config for that release, possible they moved it to a .d directory or something. Still works here ;(. @Guilherme
  • tresf
    tresf almost 5 years
    Confirmed that even on Ubuntu 18.04, ~/.config/gtk-3.0/settings.ini has no effect on "dark mode" (rebooted after change as well to restart display manager).
  • tresf
    tresf almost 5 years
    Gnome Tweak Tool doesn't offer this checkbox in 18.04 although switching to gsettings get org.gnome.desktop.interface gtk-theme does show the Adwaita-dark when it's been selected. Firefox, Java and most other apps switch using the Tweak Tool. Has the technique changed?
  • oemb1905
    oemb1905 almost 5 years
    If the solution is out of date (this was response to Ubuntu 15), then post an updated solution! As for Gnome Tweak Tool - this is supposed to be a thread for doing through Terminal - not through Tweaks. @tresf
  • Robin Métral
    Robin Métral about 4 years
    @tresf's comments are useful to others (hi!) since they at least mention an alternative solution to get a dark theme on Ubuntu. In contrast, this answer isn't useful to anybody anymore, assuming nobody runs the deprecated Ubuntu 15. Please update your answer to mention that this doesn't work for Ubuntu 16.04 and above (it's a conditional subjective)
  • oemb1905
    oemb1905 about 4 years
    @RobinMétral - the instructions are identical, except for GTK 4.0, on Ubuntu 20.04, which I am running this moment. Thanks for your comment.
  • oemb1905
    oemb1905 about 4 years
    @RobinMétral in case the GTK version was the source of confusion, it is now changed.
  • tresf
    tresf about 4 years
    @RobinMétral gsettings solution provided in a separate answer, which should work on Ubuntu 18.04, 20.04.
  • oemb1905
    oemb1905 almost 3 years
    Nothing "modern" here, just use Gnome's gsettings tool to edit the configuration files instead of a text editor.
  • user2364305
    user2364305 over 2 years
    This worked GREAT with Firefox. I used /usr/bin/gsettings set org.gnome.desktop.interface gtk-theme 'Adwaita-dark' to automatically set dark mode near sunset. askubuntu.com/questions/742870/…
  • oemb1905
    oemb1905 over 2 years
    Still working in 2021 😅
  • Victor
    Victor about 2 years
    This doesn't seem to work for me using i3. I can change the theme using gsettings, but it doesn't take effect unless I restart the application in question. Any idea what I can do to fix this? Any dark/light mode managers I'm running don't work/are pointless because of this, for me.
  • tresf
    tresf about 2 years
    @Victor perhaps this? reddit.com/r/i3wm/comments/kiy0v0/comment/gngcb5r/…. Just a guess though. I would strongly recommend you start a new question so that users running i3 can work together to find out a solution.
  • Victor
    Victor about 2 years
    @tresf Lovely! Thanks so much, this is exactly what I needed for it to work. <3
  • Admin
    Admin almost 2 years
    dconf-editor says: /org/gnome/desktop/interface/color-scheme 'prefer-dark': No schema available. A schema is what describes the use of a key, and Dconf Editor can't find one associated with this key. If the application that was using this key has been uninstalled, or if this key is obsolete, you may want to erase it. I'm on Fedora 36.
  • Admin
    Admin almost 2 years
    Follow up: I noticed this message went away when I switched from flatpak to package version of dconf-editor, even though the flatpak had access to all system libraries and gsettings-desktop-schemas is installed. But anyway, package version seems to "like" 'prefer-dark' just fine, flatpak might be working despite error message but not sure (nothing changed other than changing out flatpak for package).