📖   Chapter 2

Installation

Learn how to setup Hammerspoon and write your first config file.

Next Chapter

Setting up the Hammerspoon program is actually pretty simple! All we need is to download it, create your config file, and open the program.

Installing Hammerspoon #

There are two ways to install the program.

Via homebrew #

If you already have Homebrew setup on your computer, just run:

copy
brew install --cask hammerspoon

This will download Hammerspoon and install it to /Applications/Hammerspoon.app.

Manually #

  1. Visit the Hammerspoon homepage.
  2. Click the Download link at the top.
  3. This will redirect you to the Github releases page.
  4. From there, download the .zip file (usually called Hammerspoon-<version number>.zip.
  5. Unzip it, and drag Hammerspoon.app to your /Applications folder.

Your first config #

Now that you have Hammerspoon installed, all you need is a config file. Open your Terminal and paste in:

copy
cat << EOF > ~/.hammerspoon/init.lua
hs.hotkey.bind({"cmd", "alt", "ctrl"}, "w", function()
  hs.alert.show("Hello World!")
end)
EOF

This will create a file at ~/.hammerspoon/init.lua containing your first couple lines of Lua! You’ve made your first keybinding, which will pop up a Hello World! message.

Run it for the first time #

  1. Double click Hammerspoon.app inside your /Applications folder.
  2. It might ask you for some accessibility permissions the first time it runs. You’ll want to give these permissions by following the prompt.
  3. Press ⌘⌥⌃W. You should see Hello World! printed on the screen!

Hammerspoon is now setup and ready for you to add your own fun config too!

Initial tips

Optional tip: add your Hammerspoon config to Git #

If you track your dotfiles in version control, I recommend adding the entire ~/.hammerspoon folder to your repository.

I have a ~/.dotfiles/hammerspoon directory in my dotfiles repo. My dotfiles setup script takes care of creating a symlink:

copy
ln -s ~/.dotfiles/hammerspoon ~/.hammerspoon

Once you do that, you can track any changes to your Hammerspoon config with the version control software of your choice. I highly recommend taking 5 minutes to do this now, before you get too deep in this course!

Initial tips