I have Night Theme Switcher which I like very much. I’ve also set up shell functions to switch theme between light and dark. What I’d really like, though, is for that to happen automatically when system theme switches.
How do I accomplish that, then? I know I’m unlikely to get it switching mid-session; I’d be satisfied with just at startup. Is there some environment variable or something that I can read to get this information in my config?
If you’re using Night Theme Switcher (which I am the developer of), you can run commands when the color scheme switches. They can be set in the extension preferences.
If you want to do it outside of Night Theme switcher, the color scheme value can be read with gsettings get org.gnome.desktop.interface color-scheme.
The way I have it set up is I have two shell functions, black and white, which change the shell theme (NTS can’t do that), and also set an environment variable named COLO that applications (i.e. Neovim) can read for their own theme. I use Fish shell so I have this variable in universal scope to persist between sessions, but the autocommand I set up in NTS (fish -c [black|white]) was setting them in global scope which shadows universal scope, so application themes weren’t switching properly. I managed to fix that by checking if COLO was defined in global scope (if set -S COLO | grep global > /dev/null) and unsetting it if so.