Created
August 15, 2023 00:44
-
-
Save unixbigot/37406dfb47b8d33fd9fdff98c0a2d3a9 to your computer and use it in GitHub Desktop.
A script for MacOS that provides a brief summary of USB devices similar to Linux lsusb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
# | |
# This script for MacOS gives a nice succinct list of all the devices on | |
# the USB bus, similar to the output of the Linux "lsusb" program. | |
# | |
use strict; | |
use warnings; | |
use v5.30; | |
use JSON; | |
use Data::Dumper qw(Dumper); | |
my $busitems = decode_json(`system_profiler -json SPUSBDataType 2>/dev/null`); | |
#say "Bus items are",Dumper($busitems); | |
sub print_item { | |
my ($indent, $item)=@_; | |
#say "Bus item ",Dumper($item); | |
print "${indent}"; | |
print("$1 ") if defined($$item{vendor_id}) && $$item{vendor_id}=~m/\((.*)\)/; | |
print $$item{_name}; | |
print(" ",(split / /,$$item{vendor_id},2)[0],":",$$item{product_id}) if $$item{vendor_id}; | |
print("\n"); | |
if ($item->{_items}) { | |
print_item($indent." ", $_) for @{$item->{_items}}; | |
} | |
} | |
print_item('', $_) foreach (@{$$busitems{SPUSBDataType}}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment