Last active
January 25, 2022 05:54
-
-
Save Mufaddal1125/c8683aa14f4e767738b67080f9e3ecd6 to your computer and use it in GitHub Desktop.
Switch themes at specified time for windows
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
PS script to switch themes at specified time.
Run with task scheduler to automate switching themes.