Monitors and a stable workplace (Hammerspoon)
A multi-monitor setup in macOS often behaves chaotically: after displays reconnect, windows “move”, the Dock may end up on the wrong screen, and the monitor layout changes unpredictably. To keep this from breaking the workplace, part of the logic is moved into Hammerspoon.
1) displayplacer + tracking connections
The screen layout is applied not by hand but through displayplacer: Hammerspoon checks for a specific display by persistent ID and understands which configuration is active now (for example, whether an iPad/Sidecar is connected).
2) Automatic layouts through scripts
Scripts are prepared for different scenarios in ~/.layouts/… (roughly “with iPad” and “without iPad”). When the set of screens changes, Hammerspoon waits a short pause, lets macOS “settle”, and then applies the right layout automatically.
3) Anti-chaos after disconnecting Sidecar/iPad
One of the most unpleasant situations: you disconnect the iPad and some windows fly off to the “outermost” screen. In this configuration Hammerspoon tracks the moment of disconnection and neatly returns such windows to the primary display, so you don’t have to search the whole room for them.
In the next post I’ll show how I bring up a WebSocket connection with OBS in Hammerspoon.