For years on macOS, the same story repeated. You want a hotkey for custom window tiling, screen locking, or reacting to a USB device. Once Raycast and BetterTouchTool hit their limits, you look at Hammerspoon—the open-source bridge between macOS system APIs and your own scripts. Then came the pause: v1 ran on Objective-C and Lua, a rare language in web and backend work that needed custom wrappers (hs.json, hs.fnutils) just for JSON and arrays. Rather than patching the old core, the authors rewrote the app from scratch in Swift. The result is Hammerspoon 2, and now you script it in JavaScript.
Why Swap Lua for Swift and JavaScriptCore
Under the hood sit Swift and JavaScriptCore—macOS's built-in JS engine, the same one powering Safari. You don't need Node.js installed; the OS executes your config directly.
Moving to JavaScript wiped out an entire layer of wrappers. Standard JSON.parse and JSON.stringify replace hs.json, Math replaces hs.math, .map(), .filter(), and .reduce() replace hs.fnutils, and console.log replaces hs.inspect.
The cleanup hit UI and events too. Five legacy UI modules (hs.drawing, hs.webview, hs.dialog, hs.alert, hs.styledtext) collapsed into one declarative SwiftUI-based hs.ui module, alongside hs.canvas. Subscriptions moved from .watcher to unified on(), off(), and once() methods, and async calls like hs.application.launchOrFocus("com.apple.Safari") and AppleScript now return Promises.
What a Working init.js Config Looks Like
On first launch, the app lets you pick a config folder (defaulting to ~/.config/Hammerspoon2/) and creates init.js. You can check the path with hs.appinfo.configPath, open the REPL console via hs.openConsole(), and browse offline docs via hs.docs.show(). Splitting large configs across files uses require("./window-management.js") with module.exports and automatic .json parsing, and the site includes a TypeScript guide. Here is the starter example from the official getting-started guide combining hotkeys, window frames, and a SwiftUI alert:
// Move the focused window to the left half of the screen
function snapWindowLeft() {
const win = hs.window.focusedWindow()
if (!win) return
const screenFrame = win.screen.frame
win.frame = new HSRect(
screenFrame.x,
screenFrame.y,
screenFrame.w / 2,
screenFrame.h
)
// Show a brief SwiftUI alert
hs.ui.alert("Saved!").duration(2).show()
}
// Hotkey using a config object
hs.hotkey.bindSpec({
mods: ["cmd", "alt"],
key: "h",
message: "Show quick alert",
pressed: snapWindowLeft
})
// Screen-lock hotkey using positional arguments
const lockScreen = hs.hotkey.bind(["cmd", "ctrl"], "l", () => {
hs.power.lockScreen()
}, null, null)
Beyond manual HSRect math, you get win.centerOnScreen() and relative grid helpers via fromUnitRect(). To move other apps' windows, macOS will ask you to grant Accessibility API (hs.ax) permission in Privacy settings.
Two technical gotchas are worth noting. First, an active hotkey, timer, or watcher stays alive even if you don't hold a variable reference—just like setTimeout in a browser. Stop them explicitly with .stop(), .disable(), or .destroy(), and inspect live objects via hs.activeObjects(). Second, hs.osascript.applescript() never rejects its Promise on failure; it always resolves, so check result.success yourself.
Practical Limits: macOS 27+, Beta Status, and Legacy Configs
The migration guide states the limits plainly. The biggest requirement is the OS: Hammerspoon 2 requires macOS 27 or newer. While v2 is now the main version on the website, it officially remains in beta, so rough edges are still possible.
Bridges to Lua are burned: there is no converter, init.lua isn't loaded, and v1 modules are incompatible. The same goes for Spoons—automation plugins—which now use .spoon2, load via hs.spoons.load(), and install from GitHub or URLs via hs.spoons.use() and install() with no central registry. Thankfully, you don't have to break a working init.lua overnight: Hammerspoon 2.app installs as a separate app with its own config folder and runs cleanly alongside v1, letting you port scripts one by one.


