Skip to content

Instantly share code, notes, and snippets.

@jstnlvns
Last active March 22, 2024 19:55
Show Gist options
  • Save jstnlvns/49bc570af6247f95f5ec54bc7824c0f2 to your computer and use it in GitHub Desktop.
Save jstnlvns/49bc570af6247f95f5ec54bc7824c0f2 to your computer and use it in GitHub Desktop.
Hammerspoon INIT
hs.window.animationDuration = 0
-- Keys Being Used
-- hyper q = Mailmate
-- hyper w = GTD
-- hyper e = File/Document Management
-- hyper/meh r = Swinson/Safari open tab in new window
-- hyper/meh t = Default Browser
-- hyper y = Emacs
-- hyper a = Forklift
-- hyper s = Standard Notes
-- hyper d = Downloads in Finder
-- hyper i = iTerm
-- hyper f = Hipchat
-- hyper/meh left = window to left half/window to left 1/3
-- hyper/meh right = window to right half/window to right 1/3
-- hyper/meh up = window to center as monitor half size/window to center as monitor third size
-- hyper enter = window to full
-- meh n
-- meh k = KIRBY
-- meh m = Safari merge all windows
-- Uses array from above to launch apps while holding Hyper key
-- Creating function to launch app
local hyper = {"cmd","alt","shift","ctrl"}
local meh = {"alt","shift","ctrl"}
local defaultbrowser = 'Safari'
launch = function(appname)
hs.application.enableSpotlightForNameSearches(true)
hs.application.launchOrFocus(appname)
end
-- Single keybinding for app launch
singleapps = {
{'q', 'Mailmate'},
{'w', 'Things3.app'},
{'e', 'Eaglefiler'},
{'r', 'Swinsian'},
{'t', defaultbrowser},
{'y', 'Emacs.app'},
{'a', 'ForkLift.app'},
{'s', 'Lightpaper'},
{'c', 'Chocolat'},
{'i', 'iTerm'},
{'f', 'Hipchat'}
}
-- binds key to app from dictionary above
for i, app in ipairs(singleapps) do
hs.hotkey.bind(hyper, app[1], function()
launch(app[2])
end)
end
-- HIdes Safari windows
hs.hotkey.bind(hyper, "h", function()
xx = hs.application.get(defaultbrowser)
xx:hide()
end)
-- Arrange windows to left/right half
hs.hotkey.bind(hyper, "Left", function()
local win = hs.window.focusedWindow()
local f = win:frame()
local screen = win:screen()
local max = screen:frame()
local cs = win:size()
f.x = max.x
f.y = max.y
f.w = max.w / 2
f.h = max.h
win:setFrame(f)
end)
hs.hotkey.bind(hyper, "Right", function()
local win = hs.window.focusedWindow()
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)
hs.hotkey.bind(hyper, "Up", function()
local win = hs.window.focusedWindow()
local f = win:frame()
local screen = win:screen()
local max = screen:frame()
f.x = max.x + (max.w / 3.5)
f.y = max.y
f.w = max.w / 2
f.h = max.h
win:setFrame(f)
end)
-- Arrange windows to left/right third
hs.hotkey.bind(meh, "Left", function()
local win = hs.window.focusedWindow()
local f = win:frame()
local screen = win:screen()
local max = screen:frame()
local cs = win:size()
f.x = max.x
f.y = max.y
f.w = max.w / 3
f.h = max.h
win:setFrame(f)
end)
hs.hotkey.bind(meh, "Right", function()
local win = hs.window.focusedWindow()
local f = win:frame()
local screen = win:screen()
local max = screen:frame()
f.x = max.x + (max.w / 1.5)
f.y = max.y
f.w = max.w / 3
f.h = max.h
win:setFrame(f)
end)
hs.hotkey.bind(meh, "Up", function()
local win = hs.window.focusedWindow()
local f = win:frame()
local screen = win:screen()
local max = screen:frame()
f.x = max.x + (max.w / 3)
f.y = max.y
f.w = max.w / 3
f.h = max.h
win:setFrame(f)
end)
-- Make window full screen
hs.hotkey.bind(hyper, "Return", function()
local win = hs.window.focusedWindow()
win:toggleFullScreen()
end)
hs.hotkey.bind(hyper, "d", function()
hs.application.launchOrFocus("Finder")
as = [[
tell application "Finder"
activate
set target of Finder window 1 to folder "Downloads" of folder "justin" of folder "Users" of startup disk
end tell
]]
hs.osascript.applescript(as)
end)
hs.hotkey.bind(meh, "N", function()
local win = hs.window.focusedWindow()
win:pushWindowNextScreen()
win:toggleFullScreen()
end)
hs.hotkey.bind(meh, 'N', hs.grid.pushWindowNextScreen)
function kirby()
test = hs.alert.show(" ¯\\_(ツ)_/¯ ", alerts_nobg, 1.5)
hs.pasteboard.setContents("¯\\_(ツ)_/¯")
end
hs.hotkey.bind(meh, 'K', kirby)
------------------------------------------------------------------------------
------------------------------------------------------------------------------
-- SAFARI STUFF STARTS
------------------------------------------------------------------------------
-- tabToNewWindow
------------------------------------------------------------------------------
-- makes new window from current tab in safari
-- could maybe send it to next monitor immediately if there is one?
------------------------------------------------------------------------------
function tabToNewWindow()
hs.application.launchOrFocus("Safari")
local safari = hs.appfinder.appFromName("Safari")
local target_item_in_menu = {"Window", "Move Tab to New Window"}
safari:selectMenuItem(target_item_in_menu)
hs.alert.show(" ⎘ ", alerts_nobg, 1.5)
end
hs.hotkey.bind(meh, 'R', tabToNewWindow)
------------------------------------------------------------------------------
-- mergeAllWindows
------------------------------------------------------------------------------
-- Merges all separate windows into one window
------------------------------------------------------------------------------
function mergeAllWindows()
hs.application.launchOrFocus("Safari")
local safari = hs.appfinder.appFromName("Safari")
local target_item_in_menu = {"Window", "Merge All Windows"}
safari:selectMenuItem(target_item_in_menu)
hs.alert.show(" ⎗ ", alerts_nobg, 1.5)
end
hs.hotkey.bind(meh, 'M', mergeAllWindows)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment