← Hammerdeck
Put your windows back when a monitor reconnects
Take a MacBook away from its desk and every window on the external display lands on the
laptop screen. Plug it back in, and putting each one back where it was is your job.
The fix is to capture the arrangement once and let a rule rebuild it
whenever that display connects. Hammerdeck does this for free, with
no scripting: about two minutes of setup.
The external display is unplugged and everything piles onto the laptop; it is plugged
back in and a rule puts all four windows back.
Set it up once
- With the monitor connected, arrange your windows on it the way you want them. Keep
Hammerdeck's own windows on the laptop screen, so they aren't captured too.
- Click Hammerdeck's menu bar icon, choose Rules…, and pick the
recipe Arrange windows on dock (“Snap your windows into place when a
display connects”).
- The rule reads “When display connects”. Click the display name and make
sure it is your external monitor, not the laptop's built-in screen: the next step captures
only windows on the display named here.
- Click Capture current layout. Every window on that monitor is recorded:
its app, and its exact position and size.
- Click Add rule.
From then on, each time that monitor connects, by cable or through a dock, the captured
windows go back onto it in the same places. To try it without unplugging, drag a couple of
those windows onto the laptop screen, then click the ▶ next to the rule in the list.
With several monitors, make one rule per display.
What to expect
- Only windows of the apps you captured are moved; everything else stays
where it is.
- Windows are matched by app name. Each captured window is one slot, filled
by that app's windows from front to back, so two windows of the same app can trade places.
To pin one, click Edit as JSON and put part of its title in that window's
titlePattern.
- Apps that are not running are skipped, and the run says which ones in
Hammerdeck's local log, along with any window macOS refused to move.
- A rule can do more than arrange windows. The same trigger can open an
app, set the wallpaper, or run any macOS Shortcut, in a chain.
- Moving windows needs the Accessibility permission; Hammerdeck explains why on first launch
before macOS asks.
And by hand, in between
For the moves you make all day, ⌃⌥⌘] throws a window to the next
display and ⌃⌥⌘Z undoes the last move. More in
moving a window to another display.
Other ways to do it
- Moom ($15) can apply a saved layout
automatically when displays are added or removed, and several smaller paid apps
do this one job.
- Hammerspoon (free, open source) can do anything
here if you write the Lua yourself. Hammerdeck grew out of years of Hammerspoon scripts, and
exists for the people who would rather not.
Hammerdeck, Rectangle or Moom compares them in
more detail.
Hammerdeck is free and open source (GPL), notarized by Apple, and runs on
macOS 13 and later.
Download Hammerdeck
Or brew install --cask kouxing2000/tap/hammerdeck