Skip to content

Instantly share code, notes, and snippets.

@lostmsu
Created October 26, 2025 20:37
Show Gist options
  • Select an option

  • Save lostmsu/cde4a8578d8e0ea1182f579f44bd4523 to your computer and use it in GitHub Desktop.

Select an option

Save lostmsu/cde4a8578d8e0ea1182f579f44bd4523 to your computer and use it in GitHub Desktop.
automatically switch between dark and light mode in Windows. Edit camera name in Auto-DarkLight and min and max brightness
function Get-CameraBrightness {
param(
[Parameter(Mandatory)]
[string]$CameraName
)
$output = ffmpeg -f dshow -i video="$CameraName" -frames:v 1 -vf "signalstats,metadata=print:key=lavfi.signalstats.YAVG:file=-" -f null - 2>&1
if (($output -join "`n") -match "signalstats\.YAVG=([\d\.]+)") {
return [double]$local:Matches[1]
} else {
throw ("Could not find brightness value in FFmpeg output: " + $output)
}
}
function Auto-DarkLight {
$b = Get-CameraBrightness "ASUS 5M webcam"
Write-Host "Brightness: $b"
if ($b -gt 120) {
Set-ItemProperty 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize' AppsUseLightTheme 1
Set-ItemProperty 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize' SystemUsesLightTheme 1
} elseif ($b -lt 110) {
Set-ItemProperty 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize' AppsUseLightTheme 0
Set-ItemProperty 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize' SystemUsesLightTheme 0
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment