Skip to main content

Workaround: Luna Secondary Won't Sleep When Luna Primary Sleeps

Is your secondary device not sleeping when the primary device goes to sleep just fine? Read here to create a workaround to force your secondary device to sleep.

Overview

When a Luna Display session is active, Luna Secondary holds background processes that prevent your secondary Mac from sleeping automatically. This means that when your host Mac's display turns off or sleeps, the secondary Mac stays awake and sits on a frozen last frame.

This article walks through a workaround that detects when your host Mac's display sleeps and immediately tells the secondary Mac to sleep as well, which clears the session properly.

NOTE:

This workaround is intended for users comfortable with Terminal and basic Mac configuration.


What you'll need

  • Both Macs on the same local network

  • Terminal access on both Macs

  • Homebrew installed on your host Mac

  • Hammerspoon (free, installed via Homebrew in Step 3)


Setup

Step 1: Enable Remote Login on the secondary Mac

  • On your secondary Mac, go to System Settings > General > Sharing and turn on Remote Login.

  • Then, on your host Mac, open Terminal and run the following to copy your SSH key over so the connection is passwordless.

  • Replace <user> with the username on your secondary Mac and <receiver-mac> with its hostname or local IP:

ssh-copy-id <user>@<receiver-mac>.local
  • To verify it worked, run:

ssh <user>@<receiver-mac>.local 'echo connected'
  • You should see connected printed back without being prompted for a password.


Step 2: Create a sleep script on the host Mac

  • On your host Mac, open Terminal and create the following file:

nano ~/.displaysleep
  • Paste this in, replacing <user> and <receiver-mac> with the same values as above:

#!/bin/bash ssh -o ConnectTimeout=5 <user>@<receiver-mac>.local 'pmset sleepnow' 2>/dev/null
  • Save and close the file (in nano: Control+O, then Control+X), then make it executable:

chmod +x ~/.displaysleep

Step 3: Install Hammerspoon and set up the sleep trigger

  • Install Hammerspoon via Homebrew:

brew install --cask hammerspoon
  • Open Hammerspoon, grant it Accessibility permission when prompted, and set it to Launch at Login in its menu bar icon.

  • Then open or create the Hammerspoon config file:

nano ~/.hammerspoon/init.lua
  • Paste in the following:

sleepWatcher = hs.caffeinate.watcher.new(function(event)   if event == hs.caffeinate.watcher.screensDidSleep then     hs.execute("/Users/<user>/.displaysleep")   end end) sleepWatcher:start()
  • Replace <user> with your host Mac's username. Save and close the file.

  • Back in Hammerspoon, click Reload Config from the menu bar icon.


Test it

  • In Terminal on your host Mac, run:

pmset displaysleepnow
  • Your secondary Mac should sleep within about a second. When your host Mac wakes up, Luna Secondary will reconnect automatically.


Why Hammerspoon instead of sleepwatcher?

Sleepwatcher is a common tool for this kind of task, but its display-sleep callback does not fire reliably on recent versions of macOS. Hammerspoon catches the display-sleep event consistently.


Notes

  • This workaround triggers on display sleep, not full system sleep. These are separate events on macOS, and display sleep is the one that matters for most setups.

  • If your host Mac is set to stay awake while plugged in but let the display turn off, this workaround should still catch that correctly.

Did this answer your question?