This is a snippet I came up with that doesn't exist anywhere else on the net (so far).
I think its the best way to programmatically detect dark mode change in Windows.
Unlike other approaches, there's no busy-waiting/polling involved.
Instead, we use the native event system to subscribe to the AppsUseLightTheme
registry key change.
A big benefit of this approach is that theme change detection is almost instantaneous.
To run this in a loop, call this script, react to it's output, then call it again. An example script is provided.