

If you want to explore the options Hammerspoon offers, check out the Getting Started Guide and the full API documentation. You might want to do something crazy like having iTunes automatically start playing when your Mac detects you are in Paris. You might want to display an alert when your battery drops below a certain percentage. Hammerspoon Hammerspoon is a OS X utility that provides a high level of customisation to control the working environment. You might want to run a series of commands when your wifi interface connects to your home network. You might want to bind a keyboard shortcut to a series of window operations, or an Applescript. This is a tool for powerful automation of OS X. Typically you would write a configuration file in Lua that connects events to actions. it is a bridge between a scripting language called Lua and OSX.
#Hammerspoon code
You can write Lua code that interacts with OS X APIs for applications, windows, mouse pointers, filesystem objects, audio devices, batteries, screens, low-level keyboard/mouse events, clipboards, location services, wifi, and more. This is very hard to describe succinctly. What gives Hammerspoon its power is a set of extensions that expose specific pieces of system functionality, to the user. At its core, it is just a bridge between the operating system and a Lua scripting engine. It lets you write Lua scripts that hook into operating system functionality, allowing you to interact with the keyboard/mouse, windows, displays, filesystem, and much more. Hammerspoon is a tool for powerful automation of OS X. Hammerspoon (desktop automation on macOS) Hammerspoon is a desktop automation framework for macOS. setContents ( choice ) focusLastFocused () hs. new ( function ( choice ) if not choice then focusLastFocused () return end hs.

On selection, copy the emoji and type it into the focused application. sortByFocusedLast ) if # lastFocused > 0 then lastFocused : focus () end end - Create the chooser. local function focusLastFocused () local wf = hs. local choices = ) end - Focus the last used window.

Build the list of emojis to be displayed. We’ll populate it with emojis once selected, the emoji will be copied to clipboard and “typed” in the focused application.Ĭopy and paste the following snippet in your a file: To do so we’ll use hs.chooser, an Hammerspoon extension that creates a Spotlight-like window that allows filtering and selecting data. Now, we’ll use Hammerspoon to load the emojis and build the search engine. It has been generated by using the utility you can find here. So what the heck is Hammerspoon you ask We l l, from its own website it says that at its core, Hammerspoon is just a bridge between the operating system and a Lua scripting engine.
#Hammerspoon archive
The archive contains a few thousands PNG images depicting the emojis and a JSON file encoding their details. Over the years, it has completely changed how I do a couple small but important tasks. At its core, Hammerspoon is just a bridge between the operating system and a Lua scripting engine.
#Hammerspoon how to
Lately, I’ve been using the awesome Hammerspoon to automate some of the aspects of macOS.Īs an example of its potential, we’ll now see how to create an interactive emoji search-engine, that will allow us to search, select and paste emojis by using their name or a few keywords.Īs a result, we’ll get something like this:īefore we begin, download this archive and unzip into your ~/.hammerspoon directory. Hammerspoon boasts two things: a truly epic project name and a lua scripting environment that hooks into extensions that allow you to control system functionality in macOS. This is a tool for powerful automation of macOS.
