Macotron

macotron.usb

List the USB devices attached to the Mac and get an event when one is plugged in or removed.

// Announce each USB device as it is plugged in.
macotron.on("usb:changed", (info) => {
  if (info.action === "add") macotron.notify.toast("USB attached", info.name);
});

Listing

list(): Array<{ name, vendor, vendorID, productID }>

The attached USB devices, including hubs. name is the product name (or the IOKit class name when the device reports none), vendor the manufacturer name or "", and vendorID and productID the USB IDs as numbers.

Devices with the same name, vendor ID, and product ID appear once, so two identical flash drives are one row.

const names = macotron.usb.list().map((d) => d.name).join(", ") || "None";
macotron.notify.toast("USB", names);

Events

usb:changed

Fires when a USB device is attached or removed. The payload is { action, name, vendor, vendorID, productID }, where action is "add" or "remove". Devices that are already attached when the plugin loads do not fire an event; call list() for those.

See also