11 of 131 min

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.

Series contents
  1. Keyboard layers
  2. Karabiner = a set of JSON rules
  3. 1) Caps Lock = Hyper
  4. 2) A layer on Space: tap = space, hold = F18
  5. 3) backtick hold = F17
  6. 4) Russian layout: targeted rules for Russian typing only
  7. Hammerspoon
  8. Window Manager in Hammerspoon
  9. Media control as scenarios in Hammerspoon
  10. Hammerspoon as a local server and a "remote control"
  11. Monitors and a stable workplace (Hammerspoon)
  12. A MIDI keyboard and OBS as a hardware controller (Hammerspoon)
  13. The topic of keyboard layers is closed for now