Skip to content

Instantly share code, notes, and snippets.

@thrashr888
Created September 27, 2017 17:15
Show Gist options
  • Save thrashr888/60514b03338a823a7c266b142dea4d54 to your computer and use it in GitHub Desktop.
Save thrashr888/60514b03338a823a7c266b142dea4d54 to your computer and use it in GitHub Desktop.
hs.hotkey.bind({"cmd", "alt", "ctrl"}, "O", function()
hs.notify.new({title="Hammerspoon", informativeText="Hello World"}):send()
end)
-- Move window up
hs.hotkey.bind({"cmd", "alt", "ctrl"}, "W", function()
local win = hs.window.focusedWindow()
local f = win:frame()
f.y = f.y - 10
win:setFrame(f)
end)
-- Move window left
hs.hotkey.bind({"cmd", "alt", "ctrl"}, "A", function()
local win = hs.window.focusedWindow()
local f = win:frame()
f.x = f.x - 10
win:setFrame(f)
end)
-- Move window down
hs.hotkey.bind({"cmd", "alt", "ctrl"}, "S", function()
local win = hs.window.focusedWindow()
local f = win:frame()
f.y = f.y + 10
win:setFrame(f)
end)
-- Move window right
hs.hotkey.bind({"cmd", "alt", "ctrl"}, "D", function()
local win = hs.window.focusedWindow()
local f = win:frame()
f.x = f.x + 10
win:setFrame(f)
end)
-- Left Screen
hs.hotkey.bind({"cmd", "alt", "ctrl"}, "Left", function()
local win = hs.window.focusedWindow()
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)
-- Right screen
hs.hotkey.bind({"cmd", "alt", "ctrl"}, "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)
-- Full Screen
hs.hotkey.bind({"cmd", "alt", "ctrl"}, "Up", function()
local win = hs.window.focusedWindow()
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)
-- Top screen
hs.hotkey.bind({"cmd", "alt", "ctrl"}, "Down", function()
local win = hs.window.focusedWindow()
local f = win:frame()
local screen = win:screen()
local max = screen:frame()
f.x = max.x
f.y = max.h / 3
f.w = max.w
f.h = max.h * 0.67
win:setFrame(f)
end)
-- Reload config
hs.hotkey.bind({"cmd", "alt", "ctrl"}, "R", function()
hs.reload()
end)
hs.alert.show("Config loaded")
-- local caffeine = hs.menubar.new()
-- function setCaffeineDisplay(state)
-- if state then
-- caffeine:setTitle("AWAKE")
-- else
-- caffeine:setTitle("SLEEPY")
-- end
-- end
-- function caffeineClicked()
-- setCaffeineDisplay(hs.caffeinate.toggle("displayIdle"))
-- end
-- if caffeine then
-- caffeine:setClickCallback(caffeineClicked)
-- setCaffeineDisplay(hs.caffeinate.get("displayIdle"))
-- end
local wifiWatcher = nil
local homeSSID = "somethingelse5"
local lastSSID = hs.wifi.currentNetwork()
function ssidChangedCallback()
newSSID = hs.wifi.currentNetwork()
if newSSID == homeSSID and lastSSID ~= homeSSID then
-- We just joined our home WiFi network
hs.audiodevice.defaultOutputDevice():setVolume(25)
elseif newSSID ~= homeSSID and lastSSID == homeSSID then
-- We just departed our home WiFi network
hs.audiodevice.defaultOutputDevice():setVolume(0)
end
lastSSID = newSSID
end
wifiWatcher = hs.wifi.watcher.new(ssidChangedCallback)
wifiWatcher:start()
-- Paste by chunk
hs.hotkey.bind({"cmd", "alt"}, "V", function() hs.eventtap.keyStrokes(hs.pasteboard.getContents()) end)
local mouseCircle = nil
local mouseCircleTimer = nil
function mouseHighlight()
-- Delete an existing highlight if it exists
if mouseCircle then
mouseCircle:delete()
if mouseCircleTimer then
mouseCircleTimer:stop()
end
end
-- Get the current co-ordinates of the mouse pointer
mousepoint = hs.mouse.getAbsolutePosition()
-- Prepare a big red circle around the mouse pointer
mouseCircle = hs.drawing.circle(hs.geometry.rect(mousepoint.x-40, mousepoint.y-40, 80, 80))
mouseCircle:setStrokeColor({["red"]=1,["blue"]=0,["green"]=0,["alpha"]=1})
mouseCircle:setFill(false)
mouseCircle:setStrokeWidth(5)
mouseCircle:show()
-- Set a timer to delete the circle after 3 seconds
mouseCircleTimer = hs.timer.doAfter(3, function() mouseCircle:delete() end)
end
hs.hotkey.bind({"cmd","alt","shift"}, "D", mouseHighlight)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment