11

... I've tried search but it gives a tons of "how to connect MTP devices"

I just want to know how to get connected device name like (Nexus 10 or Galaxy S5), that I can see in Nautilus device list.

2 Answers 2

13

I found this surprisingly tough. I have a Nexus 5 and KDE (using libmtp, I think) displays it as a Nexus 5. My first instinct was that KDE was simply looking at the hardware database. This maps vendor and product strings from USB devices to known names. Here's the problem:

$ lsusb
Bus 002 Device 011: ID 18d1:4ee1 Google Inc. Nexus 4

My Nexus 5 just got a downgrade! So KDE isn't getting it from there.

We can use udevadm to query devices. In this case we need to pass it a reference to the device. I'm going to use the bus/device numbers from above (they need to be %03d formatted, so 1 becomes 001, 20 becomes 020, etc):

$ udevadm info --name=/dev/bus/usb/002/011
...
E: ID_MODEL=Nexus_5
E: ID_MODEL_ENC=Nexus\x205
E: ID_MODEL_FROM_DATABASE=Nexus 4
...

There's a lot of other crap in there but ID_MODEL seems to be what we want. If you need to further extract and process that, you could run it through awk (or another) to clean it up and replace the underscore:

$ ... | awk -F'=' '/ID_MODEL=/{gsub("_"," ");print $2}'
Nexus 5
2
  • as I'm running it from udev/rules script $env{ID_MODEL} works like a charm, thank you Jul 7, 2014 at 12:02
  • Ah, even better.
    – Oli
    Jul 7, 2014 at 12:09
8

You can parse the output of mtp-detect.

First install mtp-tools:

sudo apt-get install mtp-tools

And run:

$ mtp-detect 2>/dev/null | grep Model:
    Model: Nexus 7 (2013) Wi-Fi
3
  • I've tried to avoid dependencies, but still thank you Jul 7, 2014 at 12:08
  • I did have a look at mtp-detect but found it seriously slow. It took 40 seconds to complete here.
    – Oli
    Jul 7, 2014 at 12:11
  • @Oli: With just my Nexus 7 plugged in, it's almost instantaneous, weird. But looking at udev is also a good choice :) Jul 7, 2014 at 12:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .