I’ve been using using Spectacle pretty heavily, but with a larger screen, I always felt like quadrants were a poor use of real estate, so I began to crack open the source code, which was pretty challenging to navigate because it’s a mix of JavaScript and Objective-C reminiscent of user interface programming from ages past. So, I turned next to Hammerspoon.
Hammerspoon uses Lua as a programming interface. I was able to automate moving windows around a 3×3 grid on the current screen with 18 lines of code.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function move_to_third(r,c) | |
local win = hs.window.focusedWindow() | |
local f = win:frame() | |
local screen = win:screen() | |
local extents = screen:frame() | |
f.x = extents.x + (extents.w / 3) * c | |
f.y = extents.y + (extents.h / 3) * r | |
f.w = extents.w / 3 | |
f.h = extents.h / 3 | |
win:setFrame(f) | |
end | |
for i=1,9 do | |
hs.hotkey.bind({"cmd", "alt", "ctrl"}, tostring(i), function() | |
move_to_third(math.floor((i–1)/3),(i–1)%3) | |
end) | |
end |