How to download photos from phone over bluetooth with ubuntu

I have a samsung sync phone. It is about two years old now. It isn’t fancy, but it has a camera and a bluetooth device.

I wrote a python script to copy photos from my phone to my laptop. Any time I take a bunch of pictures, I just run
$ getpics.py
and if my phone is anywhere nearby, my computer will pull all the photos off my phone.

Bluetooth is a great little tool and I’m surprised it hasn’t caught on more with people like us. I’ve been able to access my phone from my laptop when I’m on the second floor and the phone is across the house and downstairs, still in my work bag. And bluetooth USB dongles are cheap (like around $9). There’s no need for carrying around USB keys or plugging in iPods. Everything should use bluetooth.

The getpics.py script requires that the phone and the laptop have already been bonded with each other. That’s not much work. Put your phone in to discoverable mode, then search for devices with your computer. When you find your phone, punch the same 4-digit PIN into the phone and your computer.

Anyway, here’s the script. I hope it helps somebody out.
#! /usr/bin/env python

# W. Matthew Wilson wrote this script and he released
# it into the public domain.

# vim: set expandtab ts=4 sw=4 filetype=python:

"""
Pull all the images off my phone.
"""

import commands, logging, os

from xml.etree import ElementTree
from xml.parsers.expat import ExpatError

logging.basicConfig(level=logging.DEBUG)

def get_list_of_pictures():

"""
Yield a list of strings, where each string is the file name of a
picture.
"""

# You'll need to change the 00:1D... stuff to your phone's
# MAC address.
# You might need to change /Graphics/ to where your phone
# stores its photos.
status, output = commands.getstatusoutput(
"obexftp -b 00:1D:F6:55:7E:D9 -l /Graphics/")

logging.debug("status of obexftp: %s" % status)

logging.info("Finished running obexftp...")

# Unfortunately, the output from obexftp includes some goofy status
# crap and then some XML data. So I parse each line separately,
# and skip the lines where parsing fails.

for line in output.split('\n'):

logging.debug("About to parse line %s." % line.strip())

try:
x = ElementTree.XML(line)
# Skip lines without a name attribute.
if 'name' not in x.keys(): continue

# Extract and yield the name
photofilename = x.get('name')

logging.debug("About to yield %s." % photofilename)

yield photofilename

logging.debug("Finished yielding %s." % photofilename)

except ExpatError:

logging.debug("This line is not valid XML: %s."
% line.strip())

def grab_pic(photofilename):

"""
Pull the photo named photofilename and save it locally.
"""

# You probably want to change this.
os.chdir("/home/matt/Documents/Photos/phonepics")

status, output = commands.getstatusoutput(
"obexftp -b 00:1D:F6:55:7E:D9 -g /Graphics/%s" % photofilename)

logging.info("Finished storing %s locally." % photofilename)

if __name__ == "__main__":

logging.info("Starting...")

for photo in get_list_of_pictures():
grab_pic(photo)

logging.info("All done!")

Published by

matt

My name is Matt Wilson and I live in Cleveland Heights, Ohio. I love random emails from strangers, so get in touch! matt@tplus1.com.

  • morgage31

    i added this to my article site.

    Thanks
    jaine
    ______________________________________________
    watch west wing online | watch lost | watch one tree hill online

  • ABENI437833752

    i added this to my collge report

    Have a nice day
    oemal
    ______________________________________________
    <a href=”http://www.SMARTSOURCENEWS.com ” target=”_blank”>pass a drug test | <a href=”http://www.PASS-ALL-DRUG-TEST.com ” target=”_blank”>pass marijuana drug test | <a href=”http://www.PASSDRUGTESTKIT.com ” target=”_blank”>pass drug testing

  • ElangoPrasiddhi

    Incollege right now will read this latter

    respect
    leabs
    ______________________________________________
    aion kina | aion kina

  • jenifier789

    I already diged this my firend.

    Thanks
    james
    ______________________________________________
    Aion Powerleveling | aion kinah

  • BradleyMorris

    Hello Guyz I added this post to my article site. You can view this here.

    Thanks
    pampe nel
    ______________________________________________
    foundation repair dallas

  • akaihola

    Backslashes missing from source code?

  • spam

  • wordpress does weird stuff to code, so maybe something isn't rendering right.

    What problems are you having?

  • akaihola

    No problems as I haven't tried out the code yet. When skimming through the code I just noticed an “output.split('n')” which doesn't make sense on line 41.

  • nice

  • That Sounds interesting, I agree with you.Please keep at your good work, I would come back often.*

  • Great post, what you said is really helpful to me. I can't agree with you anymore. I have been talking with my friend about, he though it is really interesting as well. Keep up with your good work, I would come back to you.

  • JonasKane

    Linux is kind of hard for simple users that like Windows. If you are indeed a Linux advanced user, this article is something that you don't need. If you are a beginner, that is probably too hard for you:))
    __________________________________________
    VoIP Phones

  • Hi Jonas,

    Thanks for the comment.

    Matt

  • JonasKane

    Linux is kind of hard for simple users that like Windows. If you are indeed a Linux advanced user, this article is something that you don't need. If you are a beginner, that is probably too hard for you:))
    __________________________________________
    VoIP Phones

  • Hi Jonas,

    Thanks for the comment.

    Matt

  • Pingback: Bluetooth applications in GNU/Linux notes | Bugdrome()