Photo by Todd Quackenbush on Unsplash

Introducing Hammerspoon — Personal Productivity

Jan-Hendrik Kuperus
2 min readMar 23, 2020

--

Hammers and spoons… Not exactly two items you’ll be using together a lot in daily life. But, when it comes to automating things in MacOS, it’s like bringing the power of shell scripting to the level of the Graphical User Interface of MacOS. I’ll leave it up to you which is the hammer and which the spoon.

So what the heck is Hammerspoon you ask? Well, from its own website it says that at its core, Hammerspoon is just a bridge between the operating system and a Lua scripting engine. That really is it. If you want it to do anything cool, you’ll have to either download a script for it, or write it yourself. Once you do, there’s not much you cannot do in MacOS.

I remember when Hammerspoon was first recommended to me. I was complaining about how applications and the MacOS system sometimes fight about keyboard shortcuts. Back then, I was outraged that some of the shortcuts of my window-management utility were hijacked by other applications. That’s when I learned how to turn my right-⌥ into a new modifier: the Hyper-key.

The creation of this Hyper-key is a post on its own. Suffice it to say it’s such an extremely powerful function, that basically all my keyboard shortcut magickery spawned from it. So is Hammerspoon just a keyboard-shortcut-creating-tool? Not at all, you can respond to a whole array of triggers, some of which I’ve listed here:

  • Watch for Application Events
  • Watch for File System Events
  • Watch for Network Events
  • Watch for Battery Events
  • etc. etc.

Just imagine what you can do with any of these triggers when you combine them with other APIs Hammerspoon offers. Here’s another non-exhaustive list of things Hammerspoon can do:

  • Control applications and windows
  • Draw directly onto the screen
  • Control your computer’s power state
  • Play sounds and music directly
  • Show informative or interactive dialogs
  • Perform actions on the filesystem
  • Perform HTTP requests
  • Host an HTTP server
  • Send iMessage or SMS through your phone
  • Run arbitrary AppleScript

As with an earlier post of mine introducing the Alfred app, this post marks the beginning of a set of posts describing automations I have built on my development system. Most of these are aimed at making my life easier, by allowing me to use as little effort as needed to get certain mundane tasks done. There are also a few more fun-inspired things you can do with Hammerspoon, those will definitely be highlighted in their own posts as well.

The next post in this series will be how to install Hammerspoon and Karabiner and how to create a new modifier for all your shortcuts: the Hyper key.

Cheers!

— JH

--

--

Jan-Hendrik Kuperus

Hi! I’m the Founder and Director of Yoink. I love writing code, tweaking it, beautifying it. I'm an all-round coder and a Professional Amateur Baker 😁🎂