Building Push-to-Talk on macOS With Hammerspoon
Vibe Coding Pad provides three mechanical keys and a separate clip-on microphone. Hammerspoon can observe one distinct macOS shortcut and run different Lua callbacks when that input is pressed and released.
Why is Hammerspoon suited to push-to-talk?
Its documented hs.hotkey.bind constructor accepts pressed, released and repeated functions. That matches the basic push-to-talk state machine: press starts capture, release ends capture and repeat does nothing. The hotkey is enabled immediately when the configuration loads.
Hammerspoon needs the appropriate macOS accessibility permission. It is a global automation layer, so a bug can affect every application. Begin with a visible alert on down and another on up before connecting a microphone or transcription process.
How should the key-down and key-up script work?
The pressed callback checks that the state is idle, records that capture began and calls a small start action. The released callback checks that recording is active, calls the matching stop action and returns to idle. Ignore duplicate downs caused by hardware repeat.
Add a timeout or separate cancel hotkey for a missing release. Do not put a long blocking command directly in the event callback. Hammerspoon exposes asynchronous task facilities, while hs.execute is more appropriate when waiting for a short command and inspecting its result is intentional.
How do you connect a dictation engine?
Use the engine's documented start and stop interface: a command-line command, URL action or supported application shortcut. Keep the adapter in one small function so changing engines does not require rewriting the input state machine. Quote absolute paths and pass no secrets in command arguments.
Test the engine manually first. Then test Hammerspoon against a disposable recording, and only afterward enable text insertion. A visible microphone-state indicator is more useful than assuming a successful process launch means capture began.
Which failures should you plan for?
Secure input, revoked accessibility permission, an occupied hotkey, a crashed engine and a lost key-up can all break the path. Focus can also change while transcription runs. Never make release automatically press Enter or submit the resulting text.
The Vibe Coding Pad leaves two controls for cancel and reviewed paste after one key becomes push-to-talk. Keep a mouse route to stop capture, log state transitions and reload the Hammerspoon configuration only after preserving a known-good copy. Keep the configuration small enough to inspect in one screen. After macOS or Hammerspoon updates, test the visual down and up alerts again before reconnecting the engine. This catches permission or event-handling changes without creating an unwanted recording or hidden background process. Keep that check in the written setup procedure.