How to set up auto dark mode on Omarchy
Most Omarchy themes are dark mode flavoured. This makes sense because most developers prefer dark mode for their terminal and editor, and Omarchy is made for developers so is all about the terminal.
I always have a permanently dark-themed terminal and editor on my Mac, but for all other apps I prefer auto-dark mode. I want my web browser to be in light mode during daylight hours, then in dark mode during the night. Same with Obsidian and any other non-terminal, non-code editing apps.
It would be nice if this was baked into Omarchy / Arch Linux but, from what I can tell, it isn't. I've solved this for now using systemd – a task manager of sorts for Linux.
Auto-dark mode using systemd
This approach involves creating a few files, all of which are saved in ~/.config/systemd/user:
.rw-r--r-- 129 olly 22 Sep 13:35 theme-dark.service
.rw-r--r-- 135 olly 22 Sep 13:35 theme-dark.timer
.rw-r--r-- 131 olly 22 Sep 13:35 theme-light.service
.rw-r--r-- 136 olly 22 Sep 13:35 theme-light.timer
.rw-r--r-- 165 olly 22 Sep 13:35 [email protected]
1. Create a theme switching service
I created a template service that is responsible for changing the system theme. I called it theme-switch@service which is the name of the file. This service takes a prefer-light or prefer-dark parameter and passes it into gsettings.
[Unit]
Description=Switch GTK theme to %i
[Service]
Type=oneshot
ExecStart=/usr/bin/gsettings set org.gnome.desktop.interface color-scheme %i
Environment=DISPLAY=:0
2. Create services to trigger each mode
Create theme-dark.service for triggering dark mode:
[Unit]
Description=Switch to dark theme
[Service]
Type=oneshot
ExecStart=systemctl --user start [email protected]
Then theme-light.service for triggering light mode:
[Unit]
Description=Switch to light theme
[Service]
Type=oneshot
ExecStart=systemctl --user start [email protected]
3. Create schedules for when to trigger each mode
theme-dark.timer to enable dark mode at 7:30pm:
[Unit]
Description=Switch to dark theme every day at 7:30 PM
[Timer]
OnCalendar=*-*-* 19:30:00
Persistent=true
[Install]
WantedBy=timers.target
theme-light.timer to enable light mode at 7:30am:
[Unit]
Description=Switch to light theme every day at 7:30 AM
[Timer]
OnCalendar=*-*-* 07:30:00
Persistent=true
[Install]
WantedBy=timers.target
4. Reload systemd
With these files in place, you just need to trigger systemctl to activate the timers:
systemctl --user daemon-reload
That's it! The mode will now switch based on the times you configured.
I accept that this is quite possibly the wrong way to accomplish this, but it's what I did and it appears to work in the way I wanted.
Please reply by email using the link below to show me a better way if you know how!