1

I'm implementing dark mode switcher for Windows 10. I've found that one can enable dark mode via

Set-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize -Name AppsUseLightTheme -Value 0 -Type Dword -Force

and light mode via

Set-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize -Name AppsUseLightTheme -Value 1 -Type Dword -Force

Now I want to implement toggling. I've tried

Get-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize -Name AppsUseLightTheme

and instead of getting 0 or 1, got output like this:

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

How do I actually get 1 to save it in a variable and do the toggling?

1 Answer 1

0

Ok, it was actually simple, had to grab the field value using dot notation:

$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

And here's an AutoHotKey script to toggle Dark Mode on 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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .