Weblog

  • Change Windows 11 Theme with PowerShell

    This PowerShell script can be used to swap between a user-created dark and light theme

    I’ve been running Debian and Arch Linux on a couple of my desktop PCs, and I am very pleased with the performance of Debian with GNOME 50, and Arch with the same. I also run Debian with KDE Plasma which is also fantastic.

    I use Windows 11 for my musical DAW software, which depends upon it. It’s not available for Linux (yet). However, I noticed something particularly annoying: there wasn’t a simple user toggle switch for something as simple as dark/light mode for the Windows 11 desktop environment. I was frustrated by this. Having to open the Settings app, select Personalization, then Themes, then to pick the dark or light theme.

    I had customized my themes to remove that ugly wallpaper that ships with Windows 11 (it looks like a mushroom or something that would grow on the side of a tree in the forest). A nice retro blue color for light mode, and a plain black background color for dark mode.

    So I consulted with Claude Opus 4.7 which came up with this PowerShell script that can detect and immediately toggle between themes. There are some caveats though:

    With dual monitors, the script causes a glitch: the taskbars on the dual monitors sometimes become out of sync theme-wise, and sometimes their fonts do the same. If you run a dual monitor setup I recommend disabling the taskbar on the secondary monitor.

    Important: Make sure you create and save a custom light theme and dark theme from within the Settings app, as they will save to your AppData\Local\Microsoft\Windows\Themes\ directory. Replace ‘MyDarkTheme.theme‘ and ‘MyLightTheme.theme‘ in the script below for them to take effect.

    # switch.ps1
    # Toggles between two saved Windows themes based on current AppsUseLightTheme value.
    
    $darkTheme  = "$env:LOCALAPPDATA\Microsoft\Windows\Themes\MyDarkTheme.theme"
    $lightTheme = "$env:LOCALAPPDATA\Microsoft\Windows\Themes\MyLightTheme.theme"
    
    # Read current mode (0 = dark, 1 = light)
    $key = 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize'
    $isLight = (Get-ItemProperty -Path $key -Name AppsUseLightTheme).AppsUseLightTheme
    
    # Pick the opposite
    $target = if ($isLight -eq 1) { $darkTheme } else { $lightTheme }
    
    if (-not (Test-Path $target)) {
        Write-Error "Theme file not found: $target"
        exit 1
    }
    
    # Apply theme. This opens Settings momentarily — we close it after.
    Start-Process -FilePath $target
    
    # Give Windows a moment to apply
    Start-Sleep -Milliseconds 1500
    
    # Close the Settings window that pops up
    Get-Process -Name "SystemSettings" -ErrorAction SilentlyContinue | Stop-Process -Force

    You need to save the script as a .ps1 file, then you can run it by double-clicking it, or, you can create a shortcut to the script, and give it a keyboard shortcut to launch it. I chose the F9 key.

    Important: If you create a shortcut to the PowerShell script, you may need to edit the shortcut target to be the following. Be sure to edit the user name in the file path:

    C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -WindowStyle Hidden -ExecutionPolicy Bypass -File "C:\Users\your_user_here\Desktop\switch.ps1"

    It works, but it’s a bit wonky admittedly. But this is the solution I went with, and will continue to use going forward. Please let us know if it works for you and you’re happy.

  • Just getting started!

    Thanks for visiting DURPANET! I’m trying to get a computer and technology collective going. Just people who share a passion for all sorts of technology old and new.

    We’re based out of Pictou County, Nova Scotia and are always looking to grow! Come say hi!