.png)
Estoy implementando un conmutador de modo oscuro para Windows 10. He encontradoesouno puede habilitar el modo oscuro a través de
Set-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize -Name AppsUseLightTheme -Value 0 -Type Dword -Force
y modo de luz a través de
Set-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize -Name AppsUseLightTheme -Value 1 -Type Dword -Force
Ahora quiero implementar la alternancia. He intentado
Get-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize -Name AppsUseLightTheme
y en lugar de obtener 0 o 1, obtuve un resultado como este:
AppsUseLightTheme : 1
PSPath : Microsoft.PowerShell.Core\Registry::HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize
PSParentPath : Microsoft.PowerShell.Core\Registry::HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes
PSChildName : Personalize
PSDrive : HKCU
PSProvider : Microsoft.PowerShell.Core\Registry
¿Cómo puedo realmente 1
guardarlo en una variable y alternar?
Respuesta1
Ok, en realidad fue simple, tuve que tomar el valor del campo usando notación de puntos:
$mode = (Get-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize -Name AppsUseLightTheme).AppsUseLightTheme
$newMode = 1 - $mode
Set-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize -Name AppsUseLightTheme -Value $newMode -Type Dword -Force
Y aquí hay un script de AutoHotKey para activar el modo oscuro en Win+ Q:
; AutoHotkey Version: 1.x
; Language: English
; Platform: Win9x/NT
; Author: Yakov Litvin
; Source: https://superuser.com/a/1724237/576393
;
; Script Function:
; toggle Windows dark mode on Win + Q
;
; based on https://stackoverflow.com/a/35844524/3995261
psScript =
(
$mode = (Get-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize -Name AppsUseLightTheme).AppsUseLightTheme
$newMode = 1 - $mode
Set-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize -Name AppsUseLightTheme -Value $newMode -Type Dword -Force
)
#vk51::Run, PowerShell.exe -Command &{%psScript%},, hide
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.