Home |
Before macOS got built-in window tiling features there weren’t too many great ways to control window panes.
You either had to pay for an app like Rectangle or Magnet and remember to download it whenever you setup a new computer, or use something like Tiles, or a full-featured window manager like Yabai.
However, since I was already using Hammerspoon for other automation, I figured it would be easiest to just repurpose it as a window management tool, partially inspired by this video.
Hammerspoon is an engine that allows you to write basic Lua scripts to interact with the UI and other elements of macOS. I use it to develop my own special keyboard shortcuts, such as:
CAPSLOCK
key into a double CTRL
/ESC
utility
key.Changing the window settings is pretty simple. After binding the modifiers and
key with hs.hotkey.bind({ "alt", "ctrl", "cmd" }, "m", someFunction)
, you
can then get the current focused window with hs.window.focusedWindow()
and
frame with win:frame()
. If you want to maximize the window, use
win:screen():fullFrame()
to get the max size and set the frame to that
size. Divide the max width by 2 and move the origin to the left or center to
half-maximize (tile to one side).
In my setup, I have the following keybinds:
CMD + ALT + CTRL + n
: Move window to next screen.CMD + ALT + CTRL + b
: Move window to previous screen.CMD + ALT + CTRL + m
: Maximize window on current screen.CMD + ALT + CTRL + o
: Half-maximize to the right.CMD + ALT + CTRL + u
: Half-maximize to the left.