Field Notes

Set up your Mac for work when you plug in a monitor

Plug a monitor into your Mac and it starts your music, opens Mail and keeps the screen awake. Unplug it and the music pauses and the Mac can sleep again.

A real run of both lanes, fed the exact payload the Display Connected and Display Disconnected triggers emit: the Mac stays awake, Mail opens and a playlist starts; then sleep is allowed again and Music pauses.

Unplug the laptop to walk to a meeting, and the music that was playing through the monitor's speakers carries on from the laptop's own, in a quiet room, until you find the pause key. Teardown is the half of a desk setup people forget.

Setup is the other half. At the desk you want Mail open, the Focus playlist going, and a big screen that does not dim while you read a long document without touching the trackpad. Away from it you want none of that.

This flow does both halves off one cable. When a display connects, it holds the Mac awake, opens Mail, and shuffles a playlist. When a display disconnects, it lets the Mac sleep again and pauses Music, but only if Music is actually open.

The flow

Ten nodes in three Sections. Two triggers feed one Condition, which splits into two lanes: At the desk on top, Away underneath.

Fig. 1Desk mode on the canvas. Two Device Event triggers feed the Plugged in? condition, whose Yes outlet runs the top lane and No outlet the bottom one.

Detect a display connecting or disconnecting

A Device Event node watches one event, so the flow has two: one set to Display Connected, one to Display Disconnected. Both are wired into the same Condition. Whichever fires starts the run with its own payload: event, displayCount (how many displays are active after the change) and timestamp.

The event values are display_connected and display_disconnected. The Condition, renamed Plugged in?, has one rule: event ends with _connected.

Fig. 2The Display disconnected trigger. Display events have no name filter. Only the USB events do.
Fig. 3Plugged in? has one rule: event ends with _connected.

Ends with, not contains, and not equals. display_disconnected contains connected, so a contains rule would send both events down the same lane. It does not end with _connected, because the character before connected is an s. The suffix rule also routes usb_connected and bluetooth_connected, so a USB or Bluetooth trigger added later needs no change here.

At the desk

Away

Fig. 4The Pause Music script checks that Music is running before it tells it to pause.
if pgrep -xq Music; then
  osascript -e 'tell application "Music" to pause'
  echo "Music paused."
else
  echo "Music was not playing."
fi

The Apple Music node's Pause action tells Music to pause, and telling an app that is not running to do anything launches it first. With the plain node, unplugging on a day you never played music would open Music. The pgrep check makes the undo lane quiet when there is nothing to undo.

Fig. 5Desk mode on, from a real run: two displays, and the track Music really started.

Permissions

Device Event needs no permission. The Apple Music node and the osascript line both drive Music through AppleScript, so the first run asks whether Watchflows may control Music. If you dismiss that, turn it back on under System Settings, Privacy & Security, Automation. The two notifications need Watchflows allowed under System Settings, Notifications.

After importing, switch the flow on with the toggle in the canvas toolbar; triggers only listen while it is enabled.

What bites in practice

A dock with two monitors fires twice. macOS reports each display separately, so a plug-in that brings up two screens runs the At the desk lane twice. Keep Mac Awake replaces its own hold and Mail is already open, but Music restarts the playlist and you get two notifications.

Other things can count as a disconnect. If you run the laptop closed on the desk, closing the lid can take the built-in display away, and the flow goes to Away while you are sitting there. Some monitors also drop off when they go to sleep, which looks the same. An iPad in Sidecar is a display too, so turning it on can count as a connect. Watch Execution History for a few days to see what your desk actually does.

The fix for both is to watch the dock rather than the screens. Replace the two display triggers with Device Event set to USB Connected and USB Disconnected, each with a Device Name Filter matching your dock or hub. The hub only disappears when the cable comes out, and the Condition already routes usb_connected and usb_disconnected. To learn the name, run a scratch flow once: Device Event on USB Connected into a Notification showing {{deviceName}}, then plug the dock in.

Keep Mac Awake stops idle sleep, not every sleep. Closing the lid off the desk or choosing Sleep still puts the Mac down, and quitting Watchflows frees it. Allow Sleep is app-wide: it clears every Keep Mac Awake hold in Watchflows, including ones other flows took.

Music only plays what is in your library. Search & Play searches your library, not the Apple Music catalogue, and matches any playlist whose name contains the query. If none does, the node fails, and Desk mode on never posts. Put your own playlist's name in Search Query.

What it cannot do

There is no node to change the display arrangement, pick the main display, switch the audio output or turn on a Focus. Nothing fires when the default audio output changes either. Run Script covers most of it, with Homebrew on its PATH:

Simulate Key Press is tempting for a window-tiling shortcut, but the keystroke lands in whichever app has focus, which is hard to predict right after a plug-in.

Variations

To build it from a sentence, paste this into the Flow Builder:

Paste into the Flow Builder

When a display connects or disconnects, check whether the event ends with "_connected". If it does, keep the Mac awake with the screen on, open /System/Applications/Mail.app, shuffle-play my Focus playlist in Apple Music, and notify me that desk mode is on. If not, allow sleep, run a bash script that pauses Music only if it is running, and notify me that desk mode is off.

Node reference: Device Event, Condition, Keep Mac Awake, Allow Sleep, Open File, Apple Music.

What's in this flow

2 triggers, one row each. Nodes are listed in the order a run reaches them; the canvas above shows where it branches.

Download this flow
  1. Device EventDisplay connected
  2. ConditionPlugged in?
  3. ActionKeep Mac Awake
  4. ActionAllow Sleep
  5. Open FileOpen Mail
  6. Run ScriptPause Music
  7. AppleApple Music
  8. NotificationDesk mode off
  9. NotificationDesk mode on
  1. Device EventDisplay disconnected
  2. joins Plugged in?

Run this one yourself

Download the flow, double-click it, and Watchflows opens it on the canvas. Everything in this note is on the 14-day free trial.