Has anyone found a way to automatically switch between "light" and "dark" modes yet, with regards to the "Window Theme" in Ubuntu's settings (Settings → Appearance → Window Theme → Light / Standard / Dark)?
Digging into the settings every morning or evening is a real pain. It'd be great to be able to automatically switch to "dark" mode at sunset, and automatically switch to "light" mode at sunrise.
For GNOME, this shell extension exists: Night Theme Switcher
It has quite a lot of options and already works out of the box, without having to configure anything, but the configuration is straight forward as well!
The terminal command for changing theme is:
for the Yaru-dark theme, and
for the Yaru-light theme.
Now, there's something called cron-job for scheduling jobs (basically executing something, repeatedly at specific time). So, you can write a cron-job to execute these commands at specified times (something like change to dark theme at 9 PM and light theme at 6 AM).
Add the following to a file named
script.sh
:Make the file executable running:
or:
Run
gnome-session-properties
in terminal. Add a new start up program by clicking add on right side and selecting thescript.sh
file by browsing and save it with some name and comment. This will tell GNOME to createlightscript.sh
anddarkscript.sh
whenever you login through GUI.Add your job (change theme) to
crontab
by using the command:and choosing a suitable editor or you can go to
/var/spool/cron/crontabs
and edit the file with your username. Accessing the file this way requiressudo
privileges. Add the following two lines (with/path/to/
replaced by actual path):It will say:
after exiting the command. You can also check with:
This should do it. The above two lines tell
cron
to executelightscript.sh
at 6:00 AM anddarkscript.sh
at 9:00 PM everyday.We are taking this detour instead of just adding:
to
crontab
because this requires theDBUS_SESSION_BUS_ADDRESS
variable to be set correctly.We can achieve this with the help of
crontab
and @shubhzgang's answer.We added
@reboot
so that script runs even if PC was shut down at cron trigger time.