A Swift command-line tool that lists USB devices connected to a Mac, similar to
Linux usbutils lsusb.
- List all connected USB devices in the Linux
lsusbone-line format - Verbose device information (
-v) - USB topology tree view (
-t) - Filter by bus/device number (
-s bus:dev) - Filter by vendor/product ID (
-d vendor:product) - No external dependencies beyond Apple's
IOKit
- macOS 12.0+
- Swift 5.5+
cd /Users/tylinux/Developer/Projects/lsusb_darwin
swift buildFor a release build:
swift build -c releasemake installInstall to a custom prefix:
make install PREFIX=$HOME/.localcp .build/release/lsusb /usr/local/bin/lsusb [options]| Option | Description |
|---|---|
-v, --version |
Show version information |
-V, --verbose |
Show detailed device information |
-t, --tree |
Show USB topology tree |
-s bus:dev |
Show only devices on the specified bus and/or device |
-d vendor:product |
Show only devices with the specified vendor and/or product ID |
-h, --help |
Show help message |
# Default listing
lsusb
# Show version
lsusb -v
# Verbose output
lsusb -V
# USB topology tree
lsusb -t
# Filter by vendor and product
lsusb -d 345f:2131
# Filter by bus only
lsusb -s 32:
# Filter by device number only
lsusb -s :3Bus 032 Device 003: ID 0x345f:0x2131 MACROSILICON OZC3-3 Video
Bus 032 Device 004: ID 0x0bda:0x8156 Realtek USB 10_100_1G_2_5G LAN
Bus 032 Device 005: ID 0x0572:0x180a HP HP Dock Audio
The tool uses Apple's IOKit framework to iterate the IOUSB registry plane,
reads properties from IOUSBHostDevice entries, and formats the results like
Linux lsusb.
Key property mappings:
Linux lsusb |
IOKit Source |
|---|---|
| Bus Number | locationID >> 24 |
| Device Number | USB Address |
| Vendor ID | idVendor |
| Product ID | idProduct |
| Vendor/Product Name | USB Vendor Name / USB Product Name |
| Serial Number | USB Serial Number |
| Speed | UsbLinkSpeed / USBSpeed / Device Speed |
This project is licensed under the MIT License. See LICENSE for details.