Created
February 13, 2024 13:14
-
-
Save sixlive/58a7e121f3cba0ca5a2e1a0146ffbcc6 to your computer and use it in GitHub Desktop.
Window sizes
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
-- Define the map of applications and their default sizes | |
local appSizeMap = { | |
["Telegram"] = {{w=470, h=900}, {w=1160, h=710}}, | |
["Todoist"] = {{w=635, h=920}, {w=1115, h=760}}, | |
["Slack"] = {{w=1300, h=780}, {w=980, h=670}}, | |
["WezTerm"] = {w=1357, h=920} | |
} | |
-- Store the current index of the size for each application | |
local appSizeIndex = {} | |
hs.hotkey.bind({}, "F14", function() | |
local win = hs.window.focusedWindow() | |
if win then | |
local appName = win:application():name() | |
local sizes = appSizeMap[appName] | |
if sizes then | |
-- Check if sizes is a single size or an array of sizes | |
if sizes.w and sizes.h then | |
sizes = { sizes } | |
end | |
-- Initialize the index for this app if it doesn't exist | |
if not appSizeIndex[appName] then | |
appSizeIndex[appName] = 1 | |
end | |
local size = sizes[appSizeIndex[appName]] | |
local frame = win:frame() | |
print(appName .. " resized from: " .. frame.w .. "x" .. frame.h) | |
print(appName .. " resized to: " .. size.w .. "x" .. size.h) | |
frame.w = size.w -- Set the width from the appSizeMap | |
frame.h = size.h -- Set the height from the appSizeMap | |
win:setFrame(frame) | |
-- Update the index, cycling back to 1 if we're at the end of the array | |
appSizeIndex[appName] = (appSizeIndex[appName] % #sizes) + 1 | |
else | |
print("No sizes found for " .. appName) | |
end | |
end | |
end) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment