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.
When I try to enable them, it tells me that "they don't exist"!
– Gregory Opera May 12 '20 at 22:52~/config/systemd/user/
. You need to create this directory if it does not exist. You don't need the separate .sh files in this example. – meuh May 13 '20 at 05:39~/.config/systemd/user/
(i.e. the hidden directory), but it tells me: `NEXT LEFT LAST PASSED UNIT ACTIVATES0 timers listed. Pass --all to see loaded but inactive timers, too.`
The same is true when I apply the
– Gregory Opera May 13 '20 at 06:34--all
flag.man systemctl
. – meuh May 13 '20 at 07:18systemctl daemon-reload
). For user sessions,systemctl --user daemon-reload
– muru May 13 '20 at 07:18systemctl --user start dark.timer
orsystemctl --user start light.timer
) to work (it didn't seem to change the theme one way or another), but when I runsystemctl --user list-timers
, it says they're running and scheduled appropriately... So I will manually change to the "dark" theme and see if it changes back in the morning. I'll probably reboot my system before I go to bed too, just to be sure... – Gregory Opera May 13 '20 at 11:43systemctl --user restart dark.timer light.timer
. I'll see if it changes back to the "light" theme in the morning, if it does, I just need to find a way to automatesystemctl --user restart dark.timer light.timer
so that I don't need to do it every time I reboot my computer... – Gregory Opera May 13 '20 at 12:54systemctl --user list-timers
it shows no timers; if I runsystemctl --user restart dark.timer light.timer
and THEN runsystemctl --user list-timers
, the timers show up and seem to work.I will open a new question for this.
– Gregory Opera May 13 '20 at 23:12