Skip to content

Instantly share code, notes, and snippets.

@shageman
Created October 21, 2021 13:00
Show Gist options
  • Save shageman/8c96204296af1af65a03e2a6aaa2fb15 to your computer and use it in GitHub Desktop.
Save shageman/8c96204296af1af65a03e2a6aaa2fb15 to your computer and use it in GitHub Desktop.
require "window_management"
require "sleep_management"
hs.loadSpoon("SpoonInstall")
spoon.SpoonInstall:andUse("CircleClock")
-- spoon.SpoonInstall:andUse("ClipboardTool",
-- {
-- config = { show_in_menubar = false, },
-- hotkeys = { toggle_clipboard = { { "cmd", "shift" }, "v" } },
-- start = true,
-- }
-- )
-- spoon.SpoonInstall:andUse("MicMute")
m = {[[Hammer time!
]]}
c = {}
function registerCommand(menuText, command, funcz)
m[#m+1] = menuText
c[#c+1] = {command, funcz}
end
registerCommand("← left 50%", "Left", left)
registerCommand("→ right 50%", "Right", right)
registerCommand("z left 33% ", "z", leftThirty)
registerCommand("a left 66% ", "a", leftSixty)
registerCommand("s center 33%", "s", centerThirty)
registerCommand("x right 33% ", "x", rightThirty)
registerCommand("d right 66% ", "d", rightSixty)
registerCommand("↑ top 50%", "Up", up)
registerCommand("↓ down 50%", "Down", down)
registerCommand("/ maximize", "/", max)
registerCommand("w writing", "w", writing)
registerCommand("c center", "c", center)
registerCommand("b book screenshot", "b", book)
myModal = hs.hotkey.modal.new({"ctrl", "alt", "cmd"}, "M", table.concat(m, "\n"))
for k, v in pairs(c) do
myModal:bind("", v[1], v[2])
end
caffeine = hs.menubar.new()
function setCaffeineDisplay(state)
if state then
caffeine:setTitle("A")
else
caffeine:setTitle("S")
end
end
function caffeineClicked()
setCaffeineDisplay(hs.caffeinate.toggle("displayIdle"))
end
if caffeine then
caffeine:setClickCallback(caffeineClicked)
setCaffeineDisplay(hs.caffeinate.get("displayIdle"))
end
function positionWindow (win, widthFrac, heightFrac, left, top)
local f = win:frame()
local screen = win:screen()
local max = screen:frame()
f.x = max.x + (max.w * left)
f.y = max.y + (max.h * top)
f.w = max.w * widthFrac
f.h = max.h * heightFrac
win:setFrame(f)
myModal:exit()
end
function left ()
positionWindow(hs.window.focusedWindow(), 1/2, 1, 0, 0)
end
function right ()
positionWindow(hs.window.focusedWindow(), 1/2, 1, 1/2, 0)
end
function leftThirty ()
positionWindow(hs.window.focusedWindow(), 1/3, 1, 0/3, 0)
end
function leftSixty ()
positionWindow(hs.window.focusedWindow(), 2/3, 1, 0/3, 0)
end
function centerThirty ()
positionWindow(hs.window.focusedWindow(), 1/3, 1, 1/3, 0)
end
function rightThirty ()
positionWindow(hs.window.focusedWindow(), 1/3, 1, 2/3, 0)
end
function rightSixty ()
positionWindow(hs.window.focusedWindow(), 2/3, 1, 1/3, 0)
end
function up ()
positionWindow(hs.window.focusedWindow(), 1, 1/2, 0, 0)
end
function down ()
positionWindow(hs.window.focusedWindow(), 1, 1/2, 0, 1/2)
end
function max ()
positionWindow(hs.window.focusedWindow(), 1, 1, 0, 0)
end
function writing ()
positionWindow(hs.window.focusedWindow(), 1/2, 1, 1/4, 0)
end
function center ()
positionWindow(hs.window.focusedWindow(), 3/4, 3/4, 1/8, 1/8)
end
function book ()
local f = hs.window.focusedWindow():frame()
local screen = hs.window.focusedWindow():screen()
local max = screen:frame()
f.x = 50
f.y = 50
f.w = 700
f.h = 420
hs.window.focusedWindow():setFrame(f)
myModal:exit()
end
hs.window.animationDuration = 0.02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment