Automatically switch to dark theme with Redshift hooks

Sometimes, I switch between a dark and a light theme on my desktop. Long before the big DE’s (or other operating systems) offered that feature via a simple button, I wrote a script to automate that task.

That script is now 6 years old and has evolved together with my desktop use. I’ve updated it with my different setups, and at some point it supported more than 5 DE’s. I have it associated to a keybinding, so the toggle is easy and fast on my dwm desktop.

For a long time, I’ve been mostly using the dark theme. However, lately I’ve found myself repeatedly switching to the light theme during daytime.

Therefore, my goal is to automate that daylight/night toggling, while keeping the possibility of manual toggling at any time.

The how

To implement that automation, the first most obvious tools we can think of using are cron or systemd-timers.

There is also a couple of projects that specifically aim to solve that. They ask you to run their daemon, which tries to switch your theme at sunrise/sunset. However, they only do it successfully on some setups (not mine), and so I’m left to provide them a custom script to execute at that time.

For me, however, the better alternative is using Redshift hooks.

Redshift is already always running on my desktop and knows when it’s night or day. It has support for hooks, which means you can drop a script in a directory, and it will be executed when some events happen, including sunset and sunrise.

It’s an elegant solution and it doesn’t require any more daemons running. This also works on Gammastep, which is a Redshift fork, just by changing the configuration directory accordingly.

If you need some inspiration, here’s my setup:


  • : Mention Gammastep

  • All posts · Show comments