Making MacOS Even Greater

By mcs94, Tue 16 April 2019, modified Tue 16 April 2019, in category Macos

automation, macos

Table of Contents

Making MacOS Even Greater

In the last post we explored a few things we can do with Hammerspoon to improve the experience of using MacOS.

This post will explore a few more cool things we can do with Hammerspoon.

Window Management

First up, window management. There are a few Spoons we can use for this, but I opted for Miro's Window Management. This one really does feel like magic.

Window Management

Once you've grabbed the spoon and dumped it into ~/.hammerspoon/Spoons/ you may call the Spoon in your init.lua file as below:


hs.window.animationDuration = 0.1
    up = {hyper, "up"},
    right = {hyper, "right"},
    down = {hyper, "down"},
    left = {hyper, "left"},
    fullscreen = {hyper, "f"}

Boiled Egg Timer

This is pretty cool. Hammerspoon functions may be triggered by using URLs beginning with hammerspoon://.

For instance, we have a function which notifies us after 6 and a half minutes:

function startEggTimer()
    hs.timer.doAfter(6.5 * 60, function (){
            title="Egg Timer!",
            informativeText="Your Egg is ready!"
    hs.alert(" Egg timer started! ")

We can bind this function to a URL using this line:

hs.urlevent.bind("eggtimer", startEggTimer)
-- Visit this url to trigger the timer:
-- hammerspoon://eggtimer

Integrating with Home Assistant

Home Assistant is a open source home automation platform. I have a basic setup for controlling a few lights.

With a little work we can detect the state of a mac:

data = '{"entity_id": "switch.macbook_power"}'

headers = {}
headers["x-ha-access"] = "your_password"

local sleepWatcher = (eventType)
    if (eventType == hs.caffeinate.watcher.systemDidWake) then"Waking up", "", "")"", data, headers)
    elseif (eventType == hs.caffeinate.watcher.systemWillSleep) then
  "Ciao", "", "")
  "", data, headers)

You'll need a corresponding switch in your home assistant configuration.

Defeating Paste Blockers

Okay, this one isn't really for defeating paste blockers (although it'll work fine for those). It's actually for dealing with the pain of pasting text into Confluence.

hs.hotkey.bind(hyper, "V", function()

Text Expander

This Github Gist by Amit Kotlovski will get you a text expander. Good enough for my needs.