Skip to content

Instantly share code, notes, and snippets.

@brianly
Forked from ojkelly/init.lua
Created July 15, 2016 13:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brianly/79edec8443ec91452592d96216989db7 to your computer and use it in GitHub Desktop.
Save brianly/79edec8443ec91452592d96216989db7 to your computer and use it in GitHub Desktop.
My hammerspoon config
local usbWatcher = nil
-- This is our usbWatcher function
-- lock when yubikey is removed
function usbDeviceCallback(data)
-- this line will let you know the name of each usb device you connect, useful for the string match below
hs.notify.show("USB", "You just connected", data["productName"])
-- Replace "Yubikey" with the name of the usb device you want to use.
if string.match(data["productName"], "Yubikey") then
if (data["eventType"] == "added") then
hs.notify.show("Yubikey", "You just connected", data["productName"])
-- wake the screen up, so knock will activate
-- get knock here http://www.knocktounlock.com
os.execute("caffeinate -u -t 5")
elseif (data["eventType"] == "removed") then
-- replace +000000000000 with a phone number registered to iMessage
hs.messages.iMessage("+000000000000", "Your Yubikey was just removed from your Work iMac.")
-- this locks to screensaver
os.execute("pmset displaysleepnow")
end
end
end
-- Start the usb watcher
usbWatcher = hs.usb.watcher.new(usbDeviceCallback)
usbWatcher:start()
-- get a dreamcheeky led screen like this http://dreamcheeky.com/led-message-board
-- get dcled from here https://github.com/kost/dcled
local usbWatcher = nil
-- This is our usbWatcher function
-- lock when yubikey is removed
function usbDeviceCallback(data)
hs.notify.show("USB", "You just connected", data["productName"])
-- Replace "Yubikey" with the name of the usb device you want to use.
if string.match(data["productName"], "Yubikey") then
if (data["eventType"] == "added") then
hs.notify.show("Yubikey", "You just connected", data["productName"])
-- wake the screen up, so knock will acti
os.execute("caffeinate -u -t 5")
setDcled('! BUSY ! BUSY ! BUSY ')
elseif (data["eventType"] == "removed") then
-- replace +000000000000 with a phone number registered to iMessage
hs.messages.iMessage("+000000000000", "Your Yubikey was just removed from your Work iMac.")
setDcled('THE DEV IS OUT')
-- this locks to screensaver
os.execute("pmset displaysleepnow")
end
end
end
-- Start the usb watcher
usbWatcher = hs.usb.watcher.new(usbDeviceCallback)
usbWatcher:start()
local dcmenubar = hs.menubar.new()
function setDcled(message)
dcmenubar:setTitle("led: " .. message)
hs.notify.show("dcled", "set:", message)
-- os.execute("ps -ef | grep dcled | grep -v grep | awk '{print $2}' | xargs kill -9")
os.execute("pkill -9 dcled")
os.execute('/usr/local/bin/dcled -s 30 --repeat -m \'' .. message .. '\' &')
end
hs.hotkey.bind({"cmd"}, "f4", function() setDcled('BUSY <---- SEE RUPERT ') end)
hs.hotkey.bind({"cmd"}, "f5", function() setDcled(':) :) :)') end)
hs.hotkey.bind({"cmd"}, "f6", function() setDcled('IN A MEETING') end)
hs.hotkey.bind({"cmd"}, "f7", function() setDcled('LUNCH') end)
hs.hotkey.bind({"cmd"}, "f8", function() setDcled('THE DEV IS OUT') end)
hs.hotkey.bind({"cmd"}, "f9", function() setDcled('THE DEV IS IN') end)
hs.hotkey.bind({"cmd"}, "f10", function() setDcled('! BUSY ! BUSY ! BUSY ') end)
hs.hotkey.bind({"cmd"}, "f11", function() setDcled(' !!! FIXING A CRITICAL BUG !!! DO NOT INTERUPT ') end)
hs.hotkey.bind({"cmd"}, "f12", function() setDcled(' !!! DO NOT INTERUPT ') end)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment