PGTS PGTS Pty. Ltd.   ACN: 007 008 568

point Site Navigation

point Other Blog Threads



  Valid HTML 4.01 Transitional

   Download Kubuntu Today

   Ubuntu

   The Power Of KDE + Ubuntu






PGTS Humble Blog

Thread: Open Source Software

Author Image Gerry Patterson. The world's most humble blogger
Edited and endorsed by PGTS, Home of the world's most humble blogger

Mounting An Android P:hone In Ubuntu 16.04


Chronogical Blog Entries:



Date: Mon, 30 Apr 2018 23:00:00 +1000

I find it quite annoying that everywhere we are being deprived of command line interfaces.

A simple thing such as mounting your Android is no longer possible. Ok I appreciate that some of these may be due to security concerns.

I created the following script to enable me to access my phone using the command line. You have to connect your phone with a USB cable and allow access, when the popup appears on your phone ... Then run this script, to create a mount that you can see from the command line:

#!/bin/bash

# ------------------------------------------------------------------------

function fatal_err {
	echo $0 ERROR: $1
	exit 1
}

# ------------------------------------------------------------------------

MNTNAME=Phone
echo $HOME | awk '{if (NF != 1) exit (1)}'
[[ $? -eq 0 ]] || fatal_err "Cannot cope with HOME: $HOME"
[[ -d $HOME ]] || fatal_err "No such folder: $HOME"
# If UID and USER are not set, you can get them with the following:
# USER=$(whomai)
# UID=$(grep $USER /etc/passwd | awk -F: '{print $3}')
# Assume that mounts need to be re-created ...
PHONEMNT=$HOME/$MNTNAME
[[ -L $PHONEMNT ]] && rm $PHONEMNT
[[ -d $PHONEMNT ]] && fatal_err "Existing Folder: $PHONEMNT"
[[ -f $PHONEMNT ]] && fatal_err "Existing File: $PHONEMNT"
[[ -L $PHONEMNT ]] && fatal_err "Cannot unlink: $PHONEMNT"
[[ -d /run/user/$UID ]] || fatal_err "No such folder: /run/user/$UID"
FOLDER=$(find /run/user/$UID/gvfs -maxdepth 2 -type d -name $MNTNAME)
[[ -z $FOLDER ]] && fatal_err "No Phone found in /run/user/$UID"
cd $HOME || fatal_err "Cannot chdir to $HOME"
ln -s $FOLDER || fatal_err "Cannot create link to: $FOLDER"
echo Created link: $PHONEMNT to $FOLDER

YMMV. I've used it on Ubuntu 16.04 ... I don't know if it will work if your user login has spaces or weird characters in it. But if it does you probably don't know much about the command line, and you wouldn't be reading this blog. It won't be long before 18.04 is here ... So I will test it out when it does.


Other Blog Posts In This Thread:

Copyright     2018, Gerry Patterson. All Rights Reserved.