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.
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.
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
- Keep Mac Awake, Scope set to Keep screen on, no timeout. It blocks display and system idle sleep until something releases it.
- Open Mail is an Open File node pointed at
/System/Applications/Mail.app. Opening an app bundle launches it, or brings it forward if it is already running. Swap in/Applications/Slack.appor whatever you start the day with. - Apple Music, Action Search & Play, Search Type Playlist, query
Focus, Shuffle on. - Desk mode on, a Notification that reads
{{displayCount}}displays and the{{trackName}}Music reports back.
Away
- Allow Sleep releases the hold.
- Pause Music is a Run Script node, not an Apple Music node, and the reason is in the script's first line.
- Desk mode off posts the script's
{{output}}.
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.
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:
shortcuts run "Work Focus"runs a Shortcut you built with the Set Focus action.displayplacer(a third-party Homebrew tool) restores a saved arrangement from a command it prints for your current setup.SwitchAudioSource -s "Studio Display Speakers"(Homebrew'sswitchaudio-osx) picks the output device.
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
- Add AirPods. A System Event trigger on Bluetooth Device Connected with a Device Name Filter of
AirPods, wired into Plugged in?, runs the desk lane when they connect. It needs Bluetooth permission, and disconnects wait three seconds so a hop to the phone and back emits nothing. - End the day from an app. An App Event trigger on Slack with App Quit, wired into Plugged in?, emits
eventasquit. That does not end with_connected, so quitting Slack runs the Away lane.
To build it from a sentence, paste this 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.