Created
February 17, 2023 15:01
-
-
Save streetturtle/1d39cb1d1b7ed45c6844d4ee23c89756 to your computer and use it in GitHub Desktop.
Hammerspoon snippet to manipulate window position/size with a shortcut
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
-- GRID | |
-- hs.window.animationDuration=0.1; | |
local hotkey = require "hs.hotkey" | |
local grid = require "hs.grid" | |
grid.MARGINX = 0 | |
grid.MARGINY = 0 | |
grid.GRIDHEIGHT = 3 | |
grid.GRIDWIDTH = 3 | |
local mod_resize = {"alt"} | |
local mod_move = {"alt", "shift"} | |
hotkey.bind(mod_resize, 'm', grid.maximizeWindow) | |
-- Move Window | |
hotkey.bind(mod_move, 'k', grid.pushWindowDown) | |
hotkey.bind(mod_move, 'i', grid.pushWindowUp) | |
hotkey.bind(mod_move, 'j', grid.pushWindowLeft) | |
hotkey.bind(mod_move, 'l', grid.pushWindowRight) | |
-- Resize Window | |
hotkey.bind(mod_resize, 'i', grid.resizeWindowShorter) | |
hotkey.bind(mod_resize, 'k', grid.resizeWindowTaller) | |
hotkey.bind(mod_resize, 'l', grid.resizeWindowWider) | |
hotkey.bind(mod_resize, 'j', grid.resizeWindowThinner) | |
hs.hotkey.bind({"alt"}, "B", 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({"alt"}, "N", 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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment