API Docs

Module for monitoring USB device connections and disconnections

Properties

This module has no properties.

Methods

hs.usb.attachedDevices() -> [[String: Any]]

Returns all currently attached USB devices.
hs.usb.attachedDevices() -> [[String: Any]]
[[String: Any]]
An array of objects describing each attached USB device. Each object has `productName` (string), `vendorName` (string), `productID` (number), and `vendorID` (number). `serialNumber` (string) and `locationID` (number) are included when available.
const devices = hs.usb.attachedDevices()
devices.forEach(d => console.log(d.vendorName + " " + d.productName))

hs.usb.addWatcher(listener) -> None

Register a listener for USB device connection and disconnection events. The listener is called with two arguments: the event type string (`"added"` or `"removed"`) and a device-info object with the same fields as `attachedDevices()`.
hs.usb.addWatcher(listener) -> None
Name Type Description
listener JSValue The function to call when a USB device is added or removed
None
const handler = (event, device) => {
  console.log(event + ": " + device.productName + " by " + device.vendorName)
}
hs.usb.addWatcher(handler)

hs.usb.removeWatcher(listener) -> None

Remove a previously registered USB event listener.
hs.usb.removeWatcher(listener) -> None
Name Type Description
listener JSValue The function originally passed to `addWatcher`
None
const handler = (event, device) => console.log(event + ": " + device.productName)
hs.usb.addWatcher(handler)
// later…
hs.usb.removeWatcher(handler)