Skip to content

Instantly share code, notes, and snippets.

@hasparus
Last active April 20, 2024 17:39
Show Gist options
  • Save hasparus/4b497d225ce126deed44168299252978 to your computer and use it in GitHub Desktop.
Save hasparus/4b497d225ce126deed44168299252978 to your computer and use it in GitHub Desktop.
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

image

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