Skip to content

Instantly share code, notes, and snippets.

@loa
Created August 29, 2019 10:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save loa/2cb3d8063d987b784966178c5bfba701 to your computer and use it in GitHub Desktop.
Save loa/2cb3d8063d987b784966178c5bfba701 to your computer and use it in GitHub Desktop.
Hammerspoon Window Columns
function moveWindowColumn(column, width)
local window = hs.window.focusedWindow()
local windowFrame = window:frame()
local screen = window:screen()
local screenFrame = screen:frame()
-- minimum 2 columns even on smaller displays
local numColumns = math.max(2, math.floor(screenFrame.w / 1100))
local remainder = screenFrame.w % numColumns
local columnWidth = math.floor(screenFrame.w / numColumns)
windowFrame.x = column * columnWidth
windowFrame.y = screenFrame.y
windowFrame.h = screenFrame.h
if (column + width) == numColumns then
-- add remainder of width to windows using last column
windowFrame.w = width * columnWidth + remainder
else
windowFrame.w = width * columnWidth
end
window:setFrame(windowFrame)
end
hs.hotkey.bind({"cmd", "ctrl"}, "1", function () moveWindowColumn(0, 1) end)
hs.hotkey.bind({"cmd", "ctrl"}, "2", function () moveWindowColumn(1, 1) end)
hs.hotkey.bind({"cmd", "ctrl"}, "3", function () moveWindowColumn(2, 1) end)
hs.hotkey.bind({"cmd", "ctrl"}, "4", function () moveWindowColumn(0, 2) end)
hs.hotkey.bind({"cmd", "ctrl"}, "5", function () moveWindowColumn(1, 2) end)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment