10 of 131 min

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.

Series contents
  1. Keyboard layers
  2. Karabiner = a set of JSON rules
  3. 1) Caps Lock = Hyper
  4. 2) A layer on Space: tap = space, hold = F18
  5. 3) backtick hold = F17
  6. 4) Russian layout: targeted rules for Russian typing only
  7. Hammerspoon
  8. Window Manager in Hammerspoon
  9. Media control as scenarios in Hammerspoon
  10. Hammerspoon as a local server and a "remote control"
  11. Monitors and a stable workplace (Hammerspoon)
  12. A MIDI keyboard and OBS as a hardware controller (Hammerspoon)
  13. The topic of keyboard layers is closed for now