← Back to context

Comment by alexfortin

12 hours ago

I use it to enable/disable the wifi when I disconnec/connect the macbook to a specific usb hub with ethernet connection:

  local usbWatcher = hs.usb.watcher.new(function(device)
    if device.productName == "EMEET SmartCam C960" then
      if device.eventType == "added" then
        hs.execute("networksetup -setairportpower en0 off")
        hs.notify.new({title="Wi-Fi", informativeText="Disabled (USB device connected)"}):send()
      elseif device.eventType == "removed" then
        hs.execute("networksetup -setairportpower en0 on")
        hs.notify.new({title="Wi-Fi", informativeText="Re-enabled (USB device removed)"}):send()
      end
    end
  end)
  usbWatcher:start()