如今大多数设备都允许自动切换暗/亮模式,但 Windows 10 似乎没有这样的功能。有办法做到这一点吗?例如使用任务计划程序?
似乎有很多关于如何以编程方式更改窗口“主题”的示例,但没有关于亮/暗模式切换的示例(可以在“设置/颜色”中为“Windows 模式”或“应用程序模式”独立设置)。
就在这里!
无缝地完成可能有点棘手,但可以通过以下步骤完成:
打开任务计划程序并使用以下设置创建一个新任务:
General
Triggers
- 添加一个“在工作站解锁”触发器
- 添加一个触发器以每小时重复一次
Actions
- 使用 Program=Powershell 和 Arguments= 添加操作
$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 脚本看起来很多都打包在一行中,但这只是我们可以将其粘贴到操作中的“参数”对话框中。让我们把它分解一下看看它做了什么:
# 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;
}
Update:
尽管非常紧凑,但在一行中维护代码可能会很麻烦,因此如果您喜欢将 PS 脚本保存在.ps1
文件,您只需输入即可从那里执行它Powershell.exe
(or pwsh.exe
)在程序框中,然后-file C:\yourscript.ps1
作为参数):
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)