r/usefulscripts • u/MilleWhisper • 13h ago
r/usefulscripts • u/Kindly-Information52 • 15h ago
[POWERSHELL] MonitorAutoSwitch - automatically moves your laptop display to the correct side of your monitor (home vs office) based on public IP
A small PowerShell tool for anyone who docks their laptop in two places with the screen on different sides.
What it does: detects your location via public IP and repositions the laptop display on the correct side (left/right) of the main monitor. Runs on logon, wake and display connect, plus a once-a-minute display-count watcher. WinForms setup wizard, system tray toggle, per-user install (no admin, lives in %LOCALAPPDATA% + Task Scheduler).
Technical notes: positions are computed from the live display widths on every run instead of stored absolute coordinates - that plus per-monitor DPI awareness (SetProcessDpiAwarenessContext) turned out to be the fix for intermittent DISP_CHANGE_FAILED (-1) errors from ChangeDisplaySettingsEx after docking.
GitHub (MIT): https://github.com/dimitrihilverda/MonitorAutoSwitch
Disclosure: written in pair-programming style with Claude. Feedback welcome.