Skip to content

Repository files navigation

lsusb for macOS

A Swift command-line tool that lists USB devices connected to a Mac, similar to Linux usbutilslsusb.

Features

  • List all connected USB devices in the Linux lsusb one-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

Requirements

  • macOS 12.0+
  • Swift 5.5+

Build

cd /Users/tylinux/Developer/Projects/lsusb_darwin
swift build

For a release build:

swift build -c release

Install

Using Make

make install

Install to a custom prefix:

make install PREFIX=$HOME/.local

Manual

cp .build/release/lsusb /usr/local/bin/

Usage

lsusb [options]

Options

OptionDescription
-v, --versionShow version information
-V, --verboseShow detailed device information
-t, --treeShow USB topology tree
-s bus:devShow only devices on the specified bus and/or device
-d vendor:productShow only devices with the specified vendor and/or product ID
-h, --helpShow help message

Examples

# 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 :3

Example Output

Bus 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

How It Works

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 lsusbIOKit Source
Bus NumberlocationID >> 24
Device NumberUSB Address
Vendor IDidVendor
Product IDidProduct
Vendor/Product NameUSB Vendor Name / USB Product Name
Serial NumberUSB Serial Number
SpeedUsbLinkSpeed / USBSpeed / Device Speed

License

This project is licensed under the MIT License. See LICENSE for details.

About

lsusb for macOS

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages