Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A PowerShell script setting light mode during the day and dark mode after 18:30.
# Set your triggers to 06:00, log in, and 18:30.
# Set this to false if you like light Windows UI.
# Personally, I'm conflicted so I change it back and forth every few months.
$SYSTEM_ALWAYS_DARK = $TRUE
$lightTheme = @{ AppsUseLightTheme = 1; SystemUsesLightTheme = 1 }
$darkTheme = @{ AppsUseLightTheme = 0; SystemUsesLightTheme = 0 }
# We set light mode between 06:00 and 18:30.
$time = Get-Date -Format 'HH:mm'
$isDay = $time -ge '06:00' -and $time -le '18:30'
if ($isDay) {
$settings = $lightTheme
} else {
$settings = $darkTheme
}
if ($SYSTEM_ALWAYS_DARK) {
$settings.SystemUsesLightTheme = 0
}
foreach ($key in $settings.Keys) {
$value = $settings[$key]
Set-ItemProperty -Path "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize" -Name $key -Value $value
}
@hasparus
Copy link
Author

hasparus commented Oct 31, 2021

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment