Skip to content

Instantly share code, notes, and snippets.

@RafhaanShah
Last active April 4, 2024 15:37
Show Gist options
  • Save RafhaanShah/9de073bd2780c2967d02131eebfef06c to your computer and use it in GitHub Desktop.
Save RafhaanShah/9de073bd2780c2967d02131eebfef06c to your computer and use it in GitHub Desktop.
Hammpersoon Configs
function audioWatcher(eventType)
-- print ("Audio Event: " .. eventType)
target = "HD Pro Webcam C920"
if(eventType == "dIn ") then
cur = hs.audiodevice.defaultInputDevice():name()
if (cur ~= target) then
dev = hs.audiodevice.findInputByName(target)
if (dev ~= nil) then
print("Setting default input device to: " .. target)
dev:setDefaultInputDevice()
end
end
end
end
hs.audiodevice.watcher.setCallback(audioWatcher)
hs.audiodevice.watcher.start()
function caffeinateWatcher(eventType)
if (eventType == hs.caffeinate.watcher.systemWillSleep or
eventType == hs.caffeinate.watcher.systemWillPowerOff) then
-- Device sleeping
print ("Going to Sleep")
elseif (eventType == hs.caffeinate.watcher.systemDidWake) then
-- Device woke up
print ("Waking from Sleep")
end
end
sleepWatcher = hs.caffeinate.watcher.new(caffeinateWatcher)
sleepWatcher:start()
workSSID = "Work"
prevSSID = ""
function ssidChangedCallback()
newSSID = hs.wifi.currentNetwork()
if newSSID == nil then
print ("WiFi Disconnected")
else
print ("WiFi Changed " .. newSSID)
end
if newSSID == workSSID then
-- We just joined our work WiFi network
print ("Work WiFi")
else
if prevSSID == workSSID then
-- We just departed our work WiFi network
print ("Left Work WiFi")
end
end
if newSSID == nil then
prevSSID = ""
else
prevSSID = newSSID
end
end
-- Run this to get location permission for WiFi print(hs.location.get())
hs.location.get()
wifiWatcher = hs.wifi.watcher.new(ssidChangedCallback)
wifiWatcher:start()
function usbDeviceCallback(data)
if (data["productName"] == "Razer Huntsman V2") then
if (data["eventType"] == "added") then
hs.keycodes.setLayout("British - PC")
elseif (data["eventType"] == "removed") then
hs.keycodes.setLayout("U.S.")
end
end
end
usbWatcher = hs.usb.watcher.new(usbDeviceCallback)
usbWatcher:start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment