-
-
Save confluencepoint/4d556d833815fa4891d3a0caaa2351b3 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 saveWindowsLayout(args) | |
local layout = {} | |
for _, w in pairs(hs.window.allWindows()) do | |
layout[tostring(w:id())] = { | |
frame = w:frame().table, | |
title = w:title(), | |
} | |
end | |
hs.settings.set("zWindowsLayout", hs.json.encode(layout)) | |
end | |
function restoreWindowsLayout() | |
local layout = hs.settings.get("zWindowsLayout") | |
if nil == layout then return end | |
hs.timer.doAfter(0, function() | |
local delay = 0.1 | |
local frameRestoreDuration = 0.3 | |
layout = hs.json.decode(layout) | |
for _, w in pairs(hs.window.allWindows()) do | |
local wLayout = layout[tostring(w:id())] | |
if wLayout then | |
local f = hs.geometry.new(wLayout["frame"]) | |
if not f:equals(w:frame()) then | |
hs.timer.doAfter(delay, function() | |
w:setFrameInScreenBounds(f, frameRestoreDuration) | |
end) | |
delay = delay + 0.1 | |
end | |
end | |
end | |
end) | |
end | |
hs.hotkey.bind({"cmd", "shift"}, "l", nil, function() | |
saveWindowsLayout() | |
hs.task.new("/usr/bin/pmset", nil, {"displaysleepnow"}):start() | |
end) | |
hs.hotkey.bind({"cmd", "shift", "option"}, "s", nil, function() | |
saveWindowsLayout() | |
hs.alert.show("Windows layout is saved.") | |
end) | |
hs.hotkey.bind({"cmd", "shift", "option"}, "r", nil, restoreWindowsLayout) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment