how to get Device id, vendor id and product id of a mounted usb device in Mac OS cocoa

wantro picture wantro · Jan 7, 2010 · Viewed 14.1k times · Source

I am trying to write a Cocoa program which detects iPods connected to Mac OS. I am listening to NSWorkspaceDidMountNotification and NSWorkspaceDidUnmountNotification for the USB device mount and unmount notifications. I can get the device path of the mounted device using NSString *path = [[notif userInfo] objectForKey:@"NSDevicePath"]; but I also need t know the Device Id, Vendor Id, Product Id etc to check whether the mounted device is an iPod. I think the way forward is IOKit. But I have a feeling that it for low level programming. Is there any other way to find these? Also, if it is IO kit is there any sample program which will give the Ids when I provide mount path?

Thanks a lot.

Answer

Foad picture Foad · Nov 2, 2019

I think you can get the product and vendor ID by

ioreg -p IOUSB -l -b | grep -E "@|idVendor|idProduct"

but not sure about the device ID. Maybe

ioreg -p IOUSB -l -b | grep -E "@|idVendor|idProduct|bcdDevice"

For my Arduino Uno these are the information I get:

+-o Arduino Uno@14100000  <class AppleUSBDevice, id 0x100000bec, registered, matched, active, busy 0 (2 ms), retain 13>
      "idProduct" = 67
      "bcdDevice" = 1
      "idVendor" = 10755