Replicating Hammerspoon window management with yabai and skhd
I’ve used Hammerspoon as a window manager for almost 10 years.
I decided to explore some of the newer tools in window management to see if I could find an alternative approach for what I do with Hammerspoon.
Using yabai
and skhd
, I wrote the following skhdrc
file that nearly reproduces the core functionality of my Hammerspoon window management code.
I have four general window management use cases:
- halves
- quarters
- maximize
- move to another display
Here’s how I implemented that with skhd
hotkeys mapped to yabai
commands:
# left halfctrl + alt + cmd - left : yabai -m window --grid 1:2:0:0:1:1
# bottom halfctrl + alt + cmd - down : yabai -m window --grid 2:1:0:1:1:1
# top halfctrl + alt + cmd - up : yabai -m window --grid 2:1:0:0:1:1
# right halfctrl + alt + cmd - right : yabai -m window --grid 1:2:1:0:1:1
# maximizectrl + alt + cmd - m : yabai -m window --grid 1:1:0:0:1:1
# top left cornerctrl + shift + alt - left : yabai -m window --grid 2:2:0:0:1:1
# top right cornerctrl + shift + alt - up : yabai -m window --grid 2:2:1:0:1:1
# bottom left cornerctrl + shift + alt - down : yabai -m window --grid 2:2:0:1:1:1
# bottom right cornerctrl + shift + alt - right : yabai -m window --grid 2:2:1:1:1:1
# prev displayctrl + alt - left : yabai -m window --display prev; yabai -m display --focus prev
# next displayctrl + alt - right : yabai -m window --display next; yabai -m display --focus next
This configuration covers all my existing window management needs. One minor inconsistency compared to my existing setup is that the window doesn’t maintain the same relative position and size when moved to a different display, but it’s a pretty subtle difference.
It seems like I might be able to solve the resizing issues using a managed layout, but this is a pretty different approach to what I currently do, so maybe another time. This mode can be enabled (per display) with:
yabai -m config layout bsp
There is also some strange behavior where when a window is full screen on my large monitor and I attempt to send it to my other screen, yabai doesn’t actually the window to the other screen and instead, it ends up somewhere on the bottom left of the larger display and I lose focus on the window. This happens when I run a hotkey bound to
yabai -m window --display prev; yabai -m display --focus prev
Recommended
Intro to skhd
I learned about skhd recently, actually after coming across the yabai project. I've been toying with the idea of moving away from Hammerspoon for my...
Mapping Caps Lock to a Hyper Key with Karabiner and Goku
Karabiner is a keyboard customizer for macOS. I've used it for a while to map my caps lock key to <kbd>cmd</kbd> + <kbd>ctrl</kbd> +...