Created
May 18, 2021 21:53
-
-
Save dmlittle/42588d6adb956d146d198ccfd5120be5 to your computer and use it in GitHub Desktop.
Hammerspoon Window Management
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
hs.hotkey.bind({"cmd", "ctrl"}, "H", function() | |
local win = hs.window.focusedWindow() | |
local f = win:frame() | |
local screen = win:screen() | |
local max = screen:frame() | |
f.x = max.x | |
f.y = max.y | |
f.w = max.w / 2 | |
f.h = max.h | |
win:setFrame(f) | |
end) | |
hs.hotkey.bind({"cmd", "ctrl"}, "L", function() | |
local win = hs.window.focusedWindow() | |
local f = win:frame() | |
local screen = win:screen() | |
local max = screen:frame() | |
f.x = max.x + (max.w / 2) | |
f.y = max.y | |
f.w = max.w / 2 | |
f.h = max.h | |
win:setFrame(f) | |
end) | |
hs.hotkey.bind({"cmd", "ctrl"}, "K", function() | |
local win = hs.window.focusedWindow() | |
local f = win:frame() | |
local screen = win:screen() | |
local max = screen:frame() | |
f.x = max.x | |
f.y = max.y | |
f.w = max.w | |
f.h = max.h | |
win:setFrame(f) | |
end) | |
hs.hotkey.bind({"cmd", "ctrl"}, "J", function() | |
-- get the focused window | |
local win = hs.window.focusedWindow() | |
-- get the screen where the focused window is displayed, a.k.a. current screen | |
local screen = win:screen() | |
-- compute the unitRect of the focused window relative to the current screen | |
-- and move the window to the next screen setting the same unitRect | |
win:move(win:frame():toUnitRect(screen:frame()), screen:next(), true, 0) | |
end) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment