Skip to content

Instantly share code, notes, and snippets.

@NanonaN

NanonaN/init.lua Secret

Created September 19, 2022 12:27
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NanonaN/1ed6e181ffe5d834ea2dfd8ab841df0b to your computer and use it in GitHub Desktop.
Save NanonaN/1ed6e181ffe5d834ea2dfd8ab841df0b to your computer and use it in GitHub Desktop.
Hammerspoon script for saving windows layout on macOS
frames = {}
hs.hotkey.bind({ "cmd", "alt" }, "S", function()
frames = {}
local windows = hs.window.allWindows()
for i, _ in ipairs(windows) do
local window = windows[i]
frames[window:id()] = window:frame()
end
hs.alert.show("Saved")
end)
hs.hotkey.bind({ "cmd", "alt", }, "R", function()
local windows = hs.window.allWindows()
for i, _ in ipairs(windows) do
local window = windows[i]
local saved_frame = frames[window:id()]
if saved_frame ~= nil then
window:setFrame(saved_frame)
end
end
hs.alert.show("Restored")
end)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment