#!/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 verbose () { system_profiler SPUSBDataType; } version () { echo "lsusb for Mac OS X 007"; } 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" string. # Also include other relevant lines. Here's an entry sample: # # 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 # # 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 devices=`echo "$rawlog" | egrep -B 2 -A 6 "Product ID" | sed 's/^--/#/'` # Iterate over each entry for device in $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 buses=`echo "$rawlog" | egrep -A 7 "Bus:" | sed 's/^--/#/'` for device in $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