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.on(event, listener) -> None

Register a listener for USB device connection and disconnection events.
hs.usb.on(event, listener) -> None
Name Type Description
event any The event to listen for
listener any Called when a matching device event occurs
None
hs.usb.on('added', device => console.log(device.vendorName + " " + device.productName + " connected"))
hs.usb.on('removed', device => console.log(device.vendorName + " " + device.productName + " removed"))

hs.usb.off(event, listener) -> None

Remove a previously registered USB device event listener.
hs.usb.off(event, listener) -> None
Name Type Description
event any The event the listener was registered for
listener any The function originally passed to `on`
None
const onAdded = device => console.log(device.productName)
hs.usb.on('added', onAdded)
// later…
hs.usb.off('added', onAdded)

hs.usb.once(event, listener) -> None

Register a listener that fires at most once for a USB device event.
hs.usb.once(event, listener) -> None
Name Type Description
event any The event to listen for
listener any Called the next time a matching device event occurs, then automatically removed
None
hs.usb.once('added', device => console.log("First device seen: " + device.productName))