Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save erbanku/eac274bc41baf6fd100013020a8de151 to your computer and use it in GitHub Desktop.
Save erbanku/eac274bc41baf6fd100013020a8de151 to your computer and use it in GitHub Desktop.
Switch between Light & Dark Mode on Windows 11 using AHK
;Switch between Light & Dark Mode on Windows 11
;IN THIS CASE, APPS ON WINDOWS 11 WILL USE LIGHT/DARK MODE
^#!A::
; read current theme
RegRead, CurrentTheme, % "HKCU\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize", % "AppsUseLightTheme"
; toggle between themes
RegWrite, REG_DWORD, % "HKCU\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize", % "AppsUseLightTheme", % 1 - CurrentTheme
Return
;IN THIS CASE, SYSTEMS ON WINDOWS 11 WILL USE LIGHT/DARK MODE
^#!L::
; read current theme
RegRead, CurrentTheme, % "HKCU\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize", % "SystemUsesLightTheme"
; toggle between themes
RegWrite, REG_DWORD, % "HKCU\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize", % "SystemUsesLightTheme", % 1 - CurrentTheme
Return
@RokeJulianLockhart
Copy link

RokeJulianLockhart commented Nov 23, 2024

Generated by AI, but tested.

@erbanku, thank you! Did you check that they ran merely without errors, or that they actually achieved the desired result?

Anyway, I've transformed them, if of use. This allows them to be invoked via Windows automation software (like Task Scheduler) more easily:

  1. Enable-DarkModeApps.PS1

    #!/usr/bin/env -S pwsh
    If ($IsWindows) {
    	If ((Test-Path -LiteralPath 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize') -NE $True) { New-Item 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize' -Force -EA SilentlyContinue };
    	New-ItemProperty -LiteralPath 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize' -Name 'AppsUseLightTheme' -Value 0 -PropertyType 'DWord' -Force -EA SilentlyContinue;
    }
    
  2. Enable-LightModeApps.PS1

    #!/usr/bin/env -S pwsh
    If ($IsWindows) {
    	If ((Test-Path -LiteralPath 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize') -NE $True) { New-Item 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize' -Force -EA SilentlyContinue };
    	New-ItemProperty -LiteralPath 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize' -Name 'AppsUseLightTheme' -Value 1 -PropertyType 'DWord' -Force -EA SilentlyContinue;
    }
  3. Enable-DarkModeSystem.PS1

    #!/usr/bin/env -S pwsh
    If ($IsWindows) {
    	If ((Test-Path -LiteralPath 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize') -NE $True) { New-Item 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize' -Force -EA SilentlyContinue };
    	New-ItemProperty -LiteralPath 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize' -Name 'SystemUsesLightTheme' -Value 0 -PropertyType 'DWord' -Force -EA SilentlyContinue;
    }
  4. Enable-LightModeSystem.PS1

    #!/usr/bin/env -S pwsh
    If ($IsWindows) {
    	If ((Test-Path -LiteralPath 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize') -NE $True) { New-Item 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize' -Force -EA SilentlyContinue };
    	New-ItemProperty -LiteralPath 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize' -Name 'SystemUsesLightTheme' -Value 1 -PropertyType 'DWord' -Force -EA SilentlyContinue;
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment