What is a command line command to toggle between the GNOME desktop dark mode and light mode?
1 Answers
(Tested on Ubuntu 22.04. This works in Ubuntu's customized Gnome session and also in the vanilla Gnome session from the vanilla-gnome-desktop
package.)
You can use the gsettings
command in a terminal to change the value of the org.gnome.desktop.interface color-scheme
setting to either prefer-dark
or prefer-light
:
$ gsettings set org.gnome.desktop.interface color-scheme prefer-dark
$ gsettings set org.gnome.desktop.interface color-scheme prefer-light
For legacy apps (for example: GNOME Terminal) you also need to set the org.gnome.desktop.interface gtk-theme
setting to either 'Adwaita-dark'
or 'Adwaita'
:
$ gsettings set org.gnome.desktop.interface gtk-theme 'Adwaita-dark'
$ gsettings set org.gnome.desktop.interface gtk-theme 'Adwaita'
Here's a shell script that will toggle between light mode and dark mode:
#!/usr/bin/env sh
set -euo
if test "$(gsettings get org.gnome.desktop.interface color-scheme)" = "'prefer-light'"; then
gsettings set org.gnome.desktop.interface color-scheme prefer-dark
gsettings set org.gnome.desktop.interface gtk-theme 'Adwaita-dark'
else
gsettings set org.gnome.desktop.interface color-scheme prefer-light
gsettings set org.gnome.desktop.interface gtk-theme 'Adwaita'
fi
You can create a custom keyboard shortcut for the script in the Settings app (under Keyboard → View and Customize Shortcuts → Custom Shortcuts):
(In the screenshot I've saved the script at ~/.gsettings/toggle-light-dark-mode.sh
and made it executable by running: chmod u+x ~/.gsettings/toggle-light-dark-mode.sh
.)

- 543
-
Thanks @Sean I might try this. I wondered, can you explain a bit what apps/software/windows will be affected by toggling? – Johan May 12 '23 at 15:54
-
I mean, will it affect websites in firefox – Johan May 13 '23 at 15:42
-
Yes if you use the Dark Reader extension and set it up to follow the system preference (it has "automation options") – icarito Nov 30 '23 at 17:12