Hammerspoon as a local server and a "remote control"
One of the most practical things in my Hammerspoon setup: it works not only as hotkeys but also as a local HTTP server. This turns the Mac into a “hub” that can be triggered with commands from other devices.
How it’s built
-
An HTTP server on a fixed port is brought up (9876 in my case).
-
Authorisation is done with a header token (X-Auth-Token) instead of Basic Auth, because that makes integrating with Shortcuts more convenient and stable.
-
There’s a simple rate limit (a minimum interval between calls) so as not to spam identical commands or run into races.
-
There’s a health check / watchdog: the server regularly checks /ping and restarts if something goes wrong. So it doesn’t “die quietly”.
What it gives in practice
The result is a very direct “remote control” where each endpoint is an action:
-
media commands for specific apps (for example, Twitch/YouTube/Spotify/Music/Podcasts/Books)
-
system commands, including pmset displaysleepnow (to quickly turn off the displays)
The key point: this isn’t a “universal button” but targeted scenarios tied to specific apps and the right sequence of steps (activation, delay, command and so on).
Architecture
-
Mac Studio acts as the hub: it performs actions locally and predictably.
-
Shortcuts on an iPhone or another Mac act as clients: press a button → an HTTP request goes out → the command runs on the Mac.
This gives the feeling of a “home remote”: control of media and system actions isn’t tied to where your hands are, which window is active or which device you’re on.
Next I’ll go through the Hammerspoon + displayplacer pairing: automatic screen layout without manual fixes.