Display mirroring with Hammerspoon

08 Dec 2025 in TIL

I need to mirror my screens periodically - enough that it's painful to go in to system settings each time and configure mirroring.

Here's a Hammerspoon snippet that will toggle mirroring. It works because allScreens returns a single value if your second screen is mirroring the first.

C34H89x and LC49G95T are my screen names, which I looked up in system settings.

lua
hs.hotkey.bind({ "cmd", "alt", "ctrl", "shift" }, "M", function()
local screens = hs.screen.allScreens()
if #screens == 1 then
screens[1]:mirrorStop()
else
local screenToMirror = hs.screen.find("C34H89x")
local screenToHide = hs.screen.find("LC49G95T")
screenToHide:mirrorOf(screenToMirror)
end
end)