How to automatically switch between Windows 10 Light and Dark themes
2020-04-11Like everybody else, Microsoft finally added the concept of a light and dark theme in Windows 10 (May 2019 Update).
The Windows explorer supports it, internet browsers support it, and many websites also automatically support and use the system theme.
Now, I want the theme to automatically adjust based on the time of the day.
Unfortunately, there is no builtin switch between light and dark in Windows...
Programmatically switching between themes
As far as I'm aware, there is no documented Windows API for now.
But the current theme is stored in the registry, and simply changing a value there is enough to apply a new theme!
Light theme:
reg add HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize /v SystemUsesLightTheme /t REG_DWORD /d 1 /f
reg add HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize /v AppsUseLightTheme /t REG_DWORD /d 1 /f
Dark theme:
reg add HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize /v SystemUsesLightTheme /t REG_DWORD /d 0 /f
reg add HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize /v AppsUseLightTheme /t REG_DWORD /d 0 /f
Task scheduler to the rescue
To actually update the theme based on the time of the day, I'm using the often forgotten Windows Task Scheduler.
It's actually pretty simple.
I have two custom scheduled basic tasks (the links point to xml files that can be imported into your Task Scheduler):
- One "Switch to Dark Theme", executing the two commands above at 20:00 every day
- One "Switch to Light Theme", executing the two commands above at 07:00 every day
Both tasks are configured to run regardless of the power source ("only if computer is on AC power" is unchecked), and "run as soon as possible after a scheduled start is missing".
Future improvements
I have been using this for a few days, and it seems to work pretty well!
This is not perfect: it uses a fixed hour as a trigger instead of the actual time the sun sets or rises, but it's simple and safe. (no external app to trust)
I wish Windows, or fl.lux, would add this as an official feature...
Anyway, enjoy!
The comment is shown highlighted below in context.
JavaScript is required to see the comments. Sorry...