Toggling Gnome Dark Mode

Gnome 45 added the ability to open the quick settings menu with Super + S. However, there's no built-in way to toggle the dark mode. You'll have to press the key combo to bring up the quick settings and then navigate to "Dark Style" with arrow keys, then hit Enter.

Here is a really simple way of toggling the dark mode in Gnome through a script that can then be added to a shortcut key combo.

Step 1

The script below tests which mode is currently active. default or prefer-light for light theme. prefer-dark for dark theme. Then sets the Gnome interface to the opposite, effectively toggling the light/dark mode.

#!/usr/bin/env bash
status=$(gsettings get "$class" "$name" | tr -d "'")
if [[ $status = "default" || $status = "prefer-light" ]]; then
gsettings set "$class" "$name" "$new_status"

Step 2

Save it as something along the line of toggle-gnome-dark-mode, make it executable and put it somewhere like /usr/local/bin. It should now be runnable straight from the command line with toggle-gnome-dark-mode

Step 3

Set the shortcut in the Settings app: Keyboard > Keyboard Shortcuts > View and Customize Shortcuts > Custom Shortcuts > +. Set it to Super + D or whatever else you prefer.

Gnome settings shortcut creation

If you want to learn how to make vim play nice(r) with light/dark mode switching read my previous post on that subject.