Hammerspoon macOS Automation
Problem
Need AHK-level desktop automation on macOS. AutoHotkey is Windows-only; macOS lacks a native scripting equivalent for window management, hotkeys, and system event handling.
Solution
Hammerspoon bridges macOS APIs and Lua scripting, providing deterministic OS control via the Accessibility API rather than input simulation.
Platform Context
| Tool | Platform | Approach |
|---|---|---|
| AutoHotkey | Windows only | Simulation-based (“sends keystrokes”) |
| Hammerspoon | macOS only | State-based (talks to window server/Accessibility API) |
| AutoKey | Linux only (X11) | Python scripting with X11 hooks |
These tools cannot coexist on the same machine — each covers one OS.
Feature Comparison vs AHK
| Feature | AutoHotkey | Hammerspoon | Edge |
|---|---|---|---|
| Hotkeys/Remapping | Gold standard, native | hs.hotkey.bind — stable, slightly verbose | Draw |
| Window Management | Requires math for snapping | Superior with hs.window + Yabai | Hammerspoon |
| GUI Creation | Easy input boxes, menus, forms | Hard — hs.webview/hs.canvas only | AHK |
| Text Expansion | Native Hotstrings | Weak — use Espanso instead | AHK |
| System Events | Limited file watchers | Superior: USB, WiFi, battery, audio, screen | Hammerspoon |
| Standalone Export | Compiles to .exe | Requires Hammerspoon installed | AHK |
Key Advantages
Watcher Pattern
AHK polls for changes (loops checking window existence). Hammerspoon uses event watchers — code fires instantly on WiFi connect, USB plug, audio device change.
Drawing Engine
hs.drawing and hs.canvas create visual overlays and HUDs far more elegantly than AHK’s tooltip system.
REPL Console
Built-in console for live Lua execution and testing — no save-and-reload cycle.
Recommended Stack
- Hammerspoon — Logic, window management, system events
- Karabiner-Elements — Low-level key remapping (before OS sees input)
- Espanso — Cross-platform text expansion
Advanced: Productivity Analysis
Hammerspoon can access macOS databases (knowledgeC.db) to detect unproductive app-switching “death loops” and trigger AI-powered interventions.
Related
- autokey-linux-automation — Linux equivalent using Python
- pyautogui-cross-platform-automation — Cross-platform GUI automation via Python