# Set current time in a variable
$time=(Get-Date).TimeOfDay.Hours;
# if later than 8am and earlier than 7pm, use light mode
if($time -gt 8 -and $time -lt 19){
"Setting Light theme.."; # output in case we let a window be opened
# set "app" system mode to "light"
Set-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize -Name AppsUseLightTheme -Value 1 -Type Dword -Force;
# set "OS" system mode to "light"
Set-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize -Name SystemUsesLightTheme -Value 1 -Type Dword -Force;
} else {
"Setting Dark theme..."; # output in case we let a window be opened
# set "app" system mode to "dark"
Set-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize -Name AppsUseLightTheme -Value 0 -Type Dword -Force;
# set "OS" system mode to "dark"
Set-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize -Name SystemUsesLightTheme -Value 0 -Type Dword -Force;
}
2条答案
按热度按时间mcvgt66p1#
是的,有!
这可能是一个有点棘手的拉小康seamesly,但它可以做到以下步骤:
打开“任务调度器”并使用以下设置创建新任务:
第一次
$time=(Get-Date).TimeOfDay.Hours; if($time -gt 8 -and $time -lt 19){"Setting Light theme..";Set-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize -Name AppsUseLightTheme -Value 1 -Type Dword -Force; Set-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize -Name SystemUsesLightTheme -Value 1 -Type Dword -Force} else {"Setting Dark theme..."; Set-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize -Name AppsUseLightTheme -Value 0 -Type Dword -Force; Set-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize -Name SystemUsesLightTheme -Value 0 -Type Dword -Force;}
的操作PS脚本看起来像是一行中包含了很多内容,但这只是为了让我们可以将其粘贴到Action中的“arguments”diaglog中。因此,让我们将其分解一下,看看它的作用:
虽然非常紧凑,但在一行中维护代码可能会很麻烦,所以如果你更喜欢将PS脚本保存在
.ps1
文件中,你可以简单地将Powershell.exe
(或pwsh.exe
)放在程序框中,然后将-file C:\yourscript.ps1
作为参数来执行它:x1c4d 1x指令集
5cg8jx4n2#
另一种方法是对所有计时使用任务计划程序,并使用
Reg
来切换注册表项。Reg
add HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize /v AppsUseLightTheme /t REG_DWORD /d 1 /f
Reg
add HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize /v AppsUseLightTheme /t REG_DWORD /d 0 /f
为每个任务启用这些设置。