#!/usr/bin/env bash # lsusb (list USB devices) utility for Mac OS X # Author: JLH, Sep 2013 # # Disclaimer: usage info and functionality from lsusb under Linux data_type () { is_before_tahoe=false mac_ver="$(sw_vers -productVersion)" major="${mac_ver%%.*}" if [ "$major" -lt 16 ]; then is_before_tahoe=true fi if $is_before_tahoe; then echo SPUSBDataType else echo SPUSBHostDataType fi } verbose () { system_profiler $(data_type); } version () { echo "lsusb for Mac OS"; } help () { cat >&2 < 1 { print prev_line; } END { ORS = ""; print line; }'` # Sort by Location ID. treedata=`echo "${treedata}" | sort` # Now strip off leading Location ID and print to stdout. for line in $treedata do echo "$line" | sed 's/^...........//' done # Restore the IFS cleanup # Not really needed, as cleanup routine does the exit. exit 0 } # Parse options while getopts ":hvpd:s:Vt" opt; do case "$opt" in h) help ; exit 0 ;; # help v) verbose ; exit 0 ;; # verbose t) tree ; exit 0 ;; # tree V) version ; exit 0 ;; # version d) vid_pid=$OPTARG ;; # filter s) bus_dev=$OPTARG ;; # filter p) parens="yes" ;; # formatter *) echo >&2 "lsusb: invalid option -- '$OPTARG'" ; help ; exit 1 esac done setup # Get all sets of lines that contain the "Product ID" or "Location ID string. # Also include other relevant lines. Here's an entry sample for Sonoma and earlier # # BRCM2046 Hub: # # Product ID: 0x4500 # Vendor ID: 0x0a5c (Broadcom Corp.) # Version: 1.00 # Speed: Up to 12 Mb/sec # Manufacturer: Apple Inc. # Location ID: 0x06100000 / 2 # Current Available (mA): 500 # Current Required (mA): 0 # # And for Tahoe and later: # # Pixel 10: # # Location ID: 0x01100000 # Connection Type: Removable # Manufacturer: Google # Serial Number: 4123ABCD # Link Speed: 480 Mb/s # USB Vendor ID: 0x18d1 # USB Product ID: 0x4ee7 # USB Product Version: 0x0601 # Power Allocated: 2.5 W (500 mA) # # Each entry will be separated by two '--' lines. We replace them # with the '#' symbol in case other parameters that contain a dash # will not be interfered # Iterate over each entry for device in "$(get_devices)" do parse if [ $? -eq 0 ]; then # Print the formatted entry echo "Bus ""$bus_num"" Device ""$device_num"": ID ""$VID"":""$PID"" ""$manufacturer"" ""$name"" ""$serial_str" fi done for device in "$(get_buses)" do parse if [ $? -eq 0 ]; then # Print the formatted entry echo "Bus ""$bus_num"" Device ""$device_num"": ID ""$VID"":""$PID"" ""$manufacturer"" ""$name"" ""$serial_str" fi done # Restore the IFS and exit cleanup