Powershell script which changes the active Windows theme and Desktop background based on daylight or a predefined schedule. Works in Windows 10/11. Not tested in Windows 7.
Auto Theme is a powerful script designed to automatically and silently switch the Windows color mode, depending on daylight or hours set by the user. It can directly activate Windows Light and Dark modes and optionally handle its own dedicated wallpapers slideshows for each, so that you can have "dark" and "light" wallpapers showing at the right times. Upon slideshow changes, it can display the name of the wallpaper in a notification or Rainmeter skin.
Alternatively, it can work by loading .theme files1. This may allow for a higher degree of customization and compatibility on certain systems.
If using .theme files and the standard Windows slideshow, displaying wallpaper names is still possible using my companion script.
Auto Theme is designed to run in the background as a scheduled task, ensuring that the system theme is updated without user intervention.
It only connects to the internet to verify Location and retrieve Sunrise and Sunset times, via free api services such as sunrisesunset.io and ip-api.com.
It can also stay completely offline by operating on fixed hours provided by the user.
When run from terminal, using the .\at.ps12 command, the script will 'toggle' the theme mode and then exit, ignoring any scheduled event.
The command .\at.ps1 can be run in terminal in verbose mode.
-
Download the latest release and extract it to your preferred folder.
-
Open the
at-config.ps1file and modify variables as preferred:
All entries in the config file come with exhaustive explanations. -
If using
.themefiles:- Make sure
$useThemeFiles = $trueis set in the config file; - Modify settings in the Personalize window (including colors or, for example, a wallpaper slideshow) and then save the theme;
In the Personalize>Themes windows, right click on a theme and select 'Save for sharing'. - Indicate the paths to the
.theme filesin the config file
- Make sure
-
(optional) Run the script
.\at-setup.ps12 to create the main scheduled task. The script will ask for system privileges if not run as admin, and then proceed to create the "Auto Theme" task. -
(alternative) You can of course create the task yourself using Task Scheduler, setting the triggers to anything you prefer. In this case, make sure that the Action is set up as follows:
- Program/script:
Powershell.exe - Add arguments:
-WindowStyle Hidden -NonInteractive -ExecutionPolicy Bypass -NoProfile -File "C:\path\to\at.ps1" - Run with highest privileges. It is advisable to always add the "On Workstation Unlock" trigger to the task. When the workstation is locked, the task may be unable to apply the theme fully, leaving out slideshow customizations and resulting in a hybrid "Custom" theme.
- Program/script:
-
When triggered, the task will then run the script
at.ps1. The script itself will schedule the next temporary task ("Sunrise Theme" or "Sunset theme") to run at the next required theme change time, whether set by the user or identified through user location. These task will be overwritten as a matter of course, to avoid clutter.
This script is designed to run from Task Scheduler, and after the initial setup doesn't need interaction from the user.
The Scheduled tasks can run the script in a completely hidden manner, or in a visible way, per user choice.
For convenience, a shortcut to the script can be created and placed on the desktop or taskbar for quick access. In this case, the shortcut should be to powershell.exe followed by the path to the script "C:\path\to\at.ps1", indicating the same path in the Start in field:
A Windows shortcut can be created to directly toggle the theme.
Workarounds have been added for a number of apps which do not toggle theme gracefully when the system theme changes. More details in the Config file.
Why, thank you for asking!
👉 You can donate to all my projects here👈
Footnotes
-
.themefiles are simple configuration instructions for the Windows pesonalization engine. You can find two examples included in this repository, with helpful comments. ↩ -
To run a PowerShell script on Windows, you need to set
Execution Policyin PowerShell, using this command:Set-ExecutionPolicy RemoteSignedas Administrator. ↩ ↩2
