One common complaint I hear from people who switch from a Windows to a Mac is that there is no native way to manage your windows on a screen. On a Windows machine, you can drag your application to one side or another and the operating system will automatically resize the window to fit exactly half of your screen. I’ll admit, it’s one of the only things that I feel like Windows does that Mac doesn’t.
But why settle for only halving your screen? If you’re like me, you like to have a handful of different applications open at once. And what if there were an easier and more flexible way to keep your windows in order?
This is where Hammerspoon comes in.
Hammerspoon does a ton of amazing things that I’m sure I’ll write more about in the future, but its window management is second to none. You can slice and dice your screen down to the pixel to fit whatever applications you want in whatever arrangement. And the best part is you aren’t limited to just one configuration — you can enable any number of keyboard shortcuts to rearrange your windows any way you please.
For this tutorial let’s stick to basics. Let’s create a hammerspoon config file that splits my monitor in three ways — IntelliJ will take up a little more than half of the screen on the left, and then the remaining 1/3 of the screen will have iTerm2 on top and Google Chrome on the bottom.
How To #
Get to know your screen size & name #
First, open your hammerspoon console and run the following commands while connected to whatever screen you want to organize. (This tutorial assumes that screen is your only screen in use).
Learn your application names #
In order to rearrange your screens, you’ll need to know their formal names that hammerspoon would recognize them as. You can do that with the following command, which will print a list of all running programs.
Build the config #
We should have everything we need now to build a config! This code will live in your ~/.hammerspoon/init.lua
file.
Hammerspoon’s docs can be a little difficult to understand if you (like me) learn just enough Lua to do what you need to do and not a line more 🥴
But the hs.geometry.rect
construct works on an X-Y axis. If you imagine the top of left of your screen as the 0, 0
location, then the hs.gemotery.rect
works like this
With that knowledge, now we can build a config that looks like this:
In that last hs.hotkey.bind
section, I’ve set up my config so that when you hit those 4 buttons at once, hammerspoon will send your applications flying to their correct homes.
Now your turn to try with your monitor (or monitors). Hopefully you know what you need to now to fall down the rabbit hole!