I am trying to get Ubuntu 20.04 LTS ("Focal Fossa") to automatically switch to the "light" Window Theme at 0600 (6AM) every morning, and the "dark" Window Theme at 1800 (6PM) every night.
The following Terminal command can be used to change to the "light" Window Theme:
gsettings set org.gnome.desktop.interface gtk-theme Yaru-light
The following Terminal command can be used to change to the "dark" Window Theme:
gsettings set org.gnome.desktop.interface gtk-theme Yaru-dark
But as noted above, I would like to automate this process.
The first suggestion presented to me was via a cron job, however this has repeatedly proved unsuccessful, so another user suggested a more "modern" approach, via Systemd "timers"... Unfortunately, I am unfamiliar with Systemd and the process of creating timers, so I have be learning as I go, without success to date.
At this time, I have six files in my "home" folder:
- dark.service
- dark.timer
- dark.sh
- light.service
- light.timer
- light.sh
The contents of "dark.service" is:
[Unit]
Description=Automatically change the "Window Theme" to "dark" in the evening.
[Service]
ExecStart=/home/gregory/dark.sh
[Install]
WantedBy=dark.sh
The contents of dark.timer is:
[Unit]
Description=Automatically change the "Window Theme" to "dark" in the evening.
[Timer]
OnCalendar=*-*-* 18:00:00
Persistent=true
[Install]
WantedBy=dark.service
The contents of "dark.sh" is:
export DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus
gsettings set org.gnome.desktop.interface gtk-theme Yaru-dark
The contents of "light.service" is:
[Unit]
Description=Automatically change the "Window Theme" to "light" in the morning.
[Service]
ExecStart=/home/gregory/light.sh
[Install]
WantedBy=light.sh
The contents of "light.timer" is:
[Unit]
Description=Automatically change the "Window Theme" to "light" in the morning.
[Timer]
OnCalendar=*-*-* 06:00:00
Persistent=true
[Install]
WantedBy=light.service
The contents of "light.sh" is:
export DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus
gsettings set org.gnome.desktop.interface gtk-theme Yaru-light
I used "Startup Application Preferences" (gnome-session-properties) to run "light.timer" and "dark.timer" on login.
Based on the advice I have been given elsewhere and what I have read online, I think creating "timers" via Systemd is probably the right approach to achieve what I want (automatic switching between "light" and "dark" Window Themes, based on the time of the day)... I just need a little help getting things working, as Systemd, timers and scripts are a whole new world to me.