Skip to content

Instantly share code, notes, and snippets.

@cklokmose
Created September 19, 2023 18:29
Show Gist options
  • Save cklokmose/1c939b743e1ec80ac8e19e9330c94342 to your computer and use it in GitHub Desktop.
Save cklokmose/1c939b743e1ec80ac8e19e9330c94342 to your computer and use it in GitHub Desktop.
My hammerspoon configuration
-- Move windows between screens
hs.hotkey.bind({"cmd", "alt", "ctrl"}, "P", function()
local win = hs.window.focusedWindow()
if not win then
return
end
win:moveToScreen(win:screen():next())
end)
-- Maximize windows
hs.hotkey.bind({"cmd", "alt", "ctrl"}, "F", function()
local win = hs.window.focusedWindow()
if not win then
return
end
local f = win:frame()
local screen = win:screen()
local max = screen:frame()
f.x = max.x
f.y = max.y
f.w = max.w
f.h = max.h
win:setFrame(f)
end)
-- Maximize window to left 50%
hs.hotkey.bind({"cmd", "alt", "ctrl"}, "Left", function()
local win = hs.window.focusedWindow()
if not win then
return
end
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)
-- Maximize window to right 50%
hs.hotkey.bind({"cmd", "alt", "ctrl"}, "Right", function()
local win = hs.window.focusedWindow()
if not win then
return
end
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)
-- Maximize window to middle 50%
hs.hotkey.bind({"cmd", "alt", "ctrl"}, "h", function()
local win = hs.window.focusedWindow()
if not win then
return
end
local f = win:frame()
local screen = win:screen()
local max = screen:frame()
f.x = max.x + (max.w / 4)
f.y = max.y
f.w = max.w / 2
f.h = max.h
win:setFrame(f)
end)
-- Maximize window to top 50%
hs.hotkey.bind({"cmd", "alt", "ctrl"}, "Up", function()
local win = hs.window.focusedWindow()
if not win then
return
end
local f = win:frame()
local screen = win:screen()
local max = screen:frame()
f.x = max.x
f.y = max.y
f.w = max.w
f.h = max.h / 2
win:setFrame(f)
end)
-- Maximize window to bottom 50%
hs.hotkey.bind({"cmd", "alt", "ctrl"}, "Down", function()
local win = hs.window.focusedWindow()
if not win then
return
end
local f = win:frame()
local screen = win:screen()
local max = screen:frame()
f.x = max.x
f.y = max.y + (max.h / 2)
f.w = max.w
f.h = max.h / 2
win:setFrame(f)
end)
-- Maximize window to left top
hs.hotkey.bind({"cmd", "alt", "ctrl"}, "I", function()
local win = hs.window.focusedWindow()
if not win then
return
end
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 / 2
win:setFrame(f)
end)
-- Maximize window to left bottom
hs.hotkey.bind({"cmd", "alt", "ctrl"}, "K", function()
local win = hs.window.focusedWindow()
if not win then
return
end
local f = win:frame()
local screen = win:screen()
local max = screen:frame()
f.x = max.x
f.y = max.y + (max.h / 2)
f.w = max.w / 2
f.h = max.h / 2
win:setFrame(f)
end)
-- Maximize window to right top
hs.hotkey.bind({"cmd", "alt", "ctrl"}, "O", function()
local win = hs.window.focusedWindow()
if not win then
return
end
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 / 2
win:setFrame(f)
end)
-- Maximize window to right bottom
hs.hotkey.bind({"cmd", "alt", "ctrl"}, "L", function()
local win = hs.window.focusedWindow()
if not win then
return
end
local f = win:frame()
local screen = win:screen()
local max = screen:frame()
f.x = max.x + (max.w / 2)
f.y = max.y + (max.h / 2)
f.w = max.w / 2
f.h = max.h / 2
win:setFrame(f)
end)
-- Close all but focused window in application
hs.hotkey.bind({"cmd", "alt", "ctrl"}, "W", function()
local win = hs.window.focusedWindow()
if not win then
return
end
local allAppWindows = hs.application.frontmostApplication():allWindows()
for _, aWindow in ipairs(allAppWindows) do
if aWindow ~= win then
aWindow:close()
end
end
end)
--- Play/pause Spotify
hs.hotkey.bind({"cmd", "alt", "ctrl"}, "s", function()
if hs.spotify.getPlaybackState() == hs.spotify.state_paused or hs.spotify.getPlaybackState() == hs.spotify.state_stopped then
hs.spotify.play()
else
hs.spotify.pause()
end
hs.spotify.displayCurrentTrack()
end)
-- Play discover weekly in Spotify
hs.hotkey.bind({"cmd", "alt", "ctrl"}, "d", function()
hs.osascript.applescript([[
tell application "Spotify"
play track "spotify:playlist:YOUR_ID_HERE"
end tell
]])
hs.spotify.displayCurrentTrack()
end)
-- Open personal zoom room
hs.hotkey.bind({"cmd", "alt", "ctrl"}, "z", function()
hs.urlevent.openURL("https://YOUR_ZOOM_ROOM_URL_HERE")
hs.pasteboard.setContents("https://YOUR_ZOOM_ROOM_URL_HERE")
end)
-- Write short email sig
hs.hotkey.bind({"cmd", "alt", "ctrl"}, "c", function()
hs.pasteboard.setContents(" - Clemens")
end)
--- Insert timestamp at cursor
hs.hotkey.bind({"cmd", "alt", "ctrl"}, "t", function()
local dateString = os.date('%d/%m %Y')
hs.eventtap.keyStrokes(dateString)
end)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment