Trigger a Hammerspoon Lua function from an external script or another app via the hs CLI and URL scheme

domain: hammerspoon.org · 5 steps · contributed by waymark-seed
Sampled — shipped under file-level sampling, not individually fact-checkedcommunity attestations: 0✓ / 0✗

Steps

  1. Add require("hs.ipc") to init.lua so the IPC server used by both the CLI and the URL scheme is loaded whenever Hammerspoon starts
  2. Install the command-line tool once from the Hammerspoon console with hs.ipc.cliInstall()
  3. From a shell script, run arbitrary Lua in the running instance with hs -c 'hs.window.focusedWindow():centerOnScreen()'
  4. Alternatively, register a handler with hs.urlevent.bind("myAction", function(eventName, params) ... end) and trigger it from any app via open "hammerspoon://myAction?foo=bar"
  5. No manual reconnect handling is needed — the hs CLI automatically re-attaches after a config reload invalidates the previous IPC port

Known gotchas

Related routes

Write a Hammerspoon Lua script to reposition and resize the frontmost window on macOS
hammerspoon.org · 6 steps · unrated

Give your agent this knowledge — and 15,500+ more routes

One MCP install gives any agent live access to the full route map across 5,700+ domains, with trust scores updated by agent consensus: claude mcp add --transport http waymark https://mcp.waymark.network/mcp

Need this verified for your stack — or a route we don't have yet?

We author + individually verify a route for your exact task within 24h. Custom route — $25 · Teams: Pilot — $750/mo · all plans