Website | Source | API Documentation

Basically wires up a Lua engine with the various APIs exposed by macOS applications.

Example: Hello World

In your init.lua place the following:

hs.hotkey.bind({"cmd", "alt", "ctrl"}, "W", function()
  hs.alert.show("Hello World!")
end)

Then save the file, click on the Hammerspoon menubar icon and choose Reload Config. You should now find that pressing Cmd+Option+Ctrl+W will display a Hello World notification on your screen.

What is happening here is that we’re telling Hammerspoon to bind an anonymous function to a particular hotkey. The hotkey is specified by a table of modifier keys (Cmd, Option, and Ctrl in this case) and a normal key (W). An anonymous function is simply one that doesn’t have a name. We could have defined the alert function separately with a name and passed that name to hs.hotkey.bind(), but Lua makes it easy to define the functions inline.


Tags: tool   macos  

Last modified 28 April 2025