Accessing my Droid Maxx from a shell script

MR ZenWiz mrzenwiz at gmail.com
Tue Dec 29 08:23:59 UTC 2015


On Thu, Dec 24, 2015 at 1:03 AM, Colin Law <clanlaw at gmail.com> wrote:
> On 23 December 2015 at 23:49, MR ZenWiz <mrzenwiz at gmail.com> wrote:
>> On Tue, Dec 22, 2015 at 11:37 PM, Colin Law <clanlaw at gmail.com> wrote:
>>> On 23 December 2015 at 00:31, MR ZenWiz <mrzenwiz at gmail.com> wrote:
>>>> I pulled down the script found here:
>>>> http://askubuntu.com/questions/342319/where-are-mtp-mounted-devices-located-in-the-filesystem/342549
>>>>
>>>> However, the top level directory is called "Internal storage" and I
>>>> haven't found a way to get the script to get through that directory.
>>>>
>>>> I've tried quoting it, adding escape characters (2-4) and that space
>>>> just won't stop interfering.
>>>>
>>>> Is there a way around this?
>>>>
>>>> From the command line it works fine, so there must be a way for a
>>>> script to do it....
>>>
>>> Put whatever you put on the command line in the script.
>>>
>> Tried that. That fails.
>
> Tried exactly what and what was the error?  We are not telepathic.
> Post the script (a very short one showing the problem) and copy/paste
> the result of running it here.  If you have spaces in file names in
> the script don't forget to put quotes round the name.
>
Here is the crux of the script:

# Find the path to MTP/PTP connected device by USB ID
find_path_by_usbid () {
    lsusboutput="$(lsusb -d $1 | head -n1)"
    usbbus="${lsusboutput% Device*}"
    usbbus="${usbbus#Bus }"
    usbdevice="${lsusboutput%%:*}"
    usbdevice="${usbdevice#*Device }"

    # Media Transfer Protocol
    if [ -d "$XDG_RUNTIME_DIR" ]; then
        runtimedir="$XDG_RUNTIME_DIR"
    else
        runtimedir="/run/user/$USER"
    fi
    MtpPath="$runtimedir/gvfs/mtp:host=%5Busb%3A${usbbus}%2C${usbdevice}%5D"
    # Picture Transfer Protocol
    PtpPath="$runtimedir/gvfs/gphoto2:host=%5Busb%3A${usbbus}%2C${usbdevice}%5D"

    if [ -d "$MtpPath" ]; then
        echo "$MtpPath"
    elif [ -d "$PtpPath" ]; then
        echo "$PtpPath"
    else
        echo "Error: File or directory was not found."
    fi
}

# USB ID for Droid Maxx
Id="22b8:2e66"
DevicePath="$(find_path_by_usbid $Id)"
echo "XT1080 path is '$DevicePath'"

# Perform an action if the device is there
if [ "$DevicePath" == "Error: File or directory was not found." ]; then
    echo "$DevicePath"
    exit
else
    indir=$DevicePath/'Internal\\ storage' ### This never works
    ls $indir
fi

The line where it has the comment "This never works" - I have tried
single and double quotes, single and double escape (backslash) in
every combination that will allow the DevicePath variable to be read,
and the result is always the same:

mar at marbase:~ $ xtlist
XT1080 path is '/run/user/500/gvfs/mtp:host=%5Busb%3A003%2C086%5D'
ls: cannot access
/run/user/500/gvfs/mtp:host=%5Busb%3A003%2C086%5D/Internal\\: No such
file or directory
ls: cannot access storage: No such file or directory

But:

mar at marbase:~ $ ls /run/user/500/gvfs/mtp:host=%5Busb%3A003%2C086%5D
Internal storage/

mar at marbase:~ $ ls
/run/user/500/gvfs/mtp:host=%5Busb%3A003%2C086%5D/Internal\ storage
Alarms/     com.vcast.mediamanager/  kindle/     Pictures/  Vault/
amazonmp3/  DCIM/     Movies/     Podcasts/
Android/    Download/     Music/     Ringtones/
Audible/    Highlight Reels/     Notifications/  SmartVoiceRecorder/

I've tried having the script cd into the directory and it still won't
list down past the top level "Internal storage."

Stumped.



More information about the ubuntu-users mailing list