Skip to content

Instantly share code, notes, and snippets.

@Mufaddal1125
Last active January 25, 2022 05:54
Show Gist options
  • Save Mufaddal1125/c8683aa14f4e767738b67080f9e3ecd6 to your computer and use it in GitHub Desktop.
Save Mufaddal1125/c8683aa14f4e767738b67080f9e3ecd6 to your computer and use it in GitHub Desktop.
Switch themes at specified time for windows
$time = Get-Date
$hourToSwitch = 18
$tillHour = 6
$shouldSwitchSystemTheme = 1
# function to get list of hours between hourtoswitch and tillhour
function GetDarkHours()
{
$hours = New-Object System.Collections.Generic.List[int]
$i = $hourToSwitch
while (1)
{
$hours.Add($i)
$i++
# if i is 24 then set it ot 0
if ($i -eq 24) {$i = 0}
# if i is equal to tillhour then break the loop. + 1 to include tillhour
if ($i -eq $tillHour + 1) { break }
}
return $hours
}
$darkHours = GetDarkHours
Write-Output $darkHours
# if time is in the dark hours then switch the system theme to dark
if ($darkHours -contains $time.Hour) {
Set-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize -Name AppsUseLightTheme -Value 0
if ($shouldSwitchSystemTheme -eq 1) {
Set-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize -Name SystemUsesLightTheme -Value 0
}
}
elseif ($darkHours -notcontains $time.Hour) {
Set-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize -Name AppsUseLightTheme -Value 1
if ($shouldSwitchSystemTheme -eq 1) {
Set-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize -Name SystemUsesLightTheme -Value 1
}
}
@Mufaddal1125
Copy link
Author

Mufaddal1125 commented Jan 23, 2022

PS script to switch themes at specified time.
Run with task scheduler to automate switching themes.

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