schussman.com logo

Sync Lightroom Galleries to Android - Automatically!

Now that I have a photogenic, tiny gurgling creature in the house, I’m shooting a lot of photos, both on the Droid X and the Pentax. Most of these photos end up, one way or another, in Lightroom for cataloguing, and as I’ve described earlier, I have a nice workflow for updating these rapidly-growing galleries on my iPad.

But how about the Droid X? It has a nice screen, and I want to foist photos of my beautiful boy on anyone I happen across — so I started to wonder if, continuing to use Lightroom as my core platform, I could keep a small gallery of photos on the Android phone with as little manual work as possible.

Here’s the executive summary: I again use a smart published collection in Lightroom to create the gallery; then I use a LaunchAgent in OS X to monitor the mount point of the Droid X on the filesystem; and a tiny shell script syncs the published gallery to the Droid whenever I plug it into the MacBook Pro. Read on for altogether too many details.

First, a couple of things to note about how the Droid X generates image galleries [ note that this may apply to all Android devices; I have no idea, and your mileage may vary ]:

  • Android automatically displays galleries based on image type — so you don’t need to update a database or anything to build your galleries on the phone. You just need folder(s) full of images.
  • When you run the Gallery app, it will display galleries with the name of the parent folder containing the images. This means you can make a folder tree on the Droid’s SD card and neatly package multiple gallery folders within it, without cluttering up your root directory.

Prepare the SD card

When I attach my Droid X via USB to the MacBook Pro, it automatically mounts it as a volume titled NO NAME, so I used the Finder to change the label to DROIDX. This, happily, seems not to have affected any of the phone’s operations; the Droid must not depend on the name of the SD card for any of its internal work.

The second preparation step is to create a master gallery directory on the SD card. This is just for housekeeping purposes; everything in the galleries will be in a subdirectory of that top-level directory. Again, I simply did this with the finder: navigate to the DROIDX drive when the phone is connected, and create a new top-level directory, Galleries.

Your SD card and Droid should now be ready to go.

Set up the Gallery/Galleries

Just like last time, I’m using smart publish collections, based on keywords, to populate the galleries that will be synced. I decided to prefix all the keywords for this usage with dx — so, dx-gallery is my main tag, and I’ve edited it in LR to not be included in export. It’s a housekeeping tag only.

I’ve tagged a bunch of images with the dx-gallery tag.

Then it’s off to build the publish service. Here’s what it looks like in the publishing manager:

And add to that service a Published Smart Set that looks like this:

You can assign multiple keywords to the Smart Set, or create as many smart sets as you want galleries, and use unique keywords to assign photos to each. Each smart set within the published collection will appear in your directory tree as a subdirectory of the top-level folder for the set — and that makes the syncing to the Droid easy.

Automate syncing via LaunchAgent

Everything I know about LaunchAgent I learned from this tutorial. This is basically a concise repeating of that description, edited for our purposes. (I’ve previously described using this process to perform system backups)

First, if it’s not already there, mkdir ~/Library/LaunchAgents. This is the folder that OS X will watch for scripts triggered by system events such as mounting an external drive, which is exactly what plugging in the Droid does.

In that directory, make a new plist file (I called mine droid-sync-watch.plist) and give paste this into it:

<?xml version=1.0 encoding=UTF-8?> <!DOCTYPE plist PUBLIC “-//Apple Computer//DTD PLIST 1.0//EN” \ “http://www.apple.com/DTDs/PropertyList-1.0.dtd”> <dict> <key>Label</key> <string>droid-sync</string> <key>LowPriorityIO</key> <true/> <key>Program</key> <string>/Users/alan/Library/Scripts/droid-sync</string> <key>ProgramArguments</key> <array> <string>droid-sync</string> </array> <key>WatchPaths</key> <array> <string>/Volumes</string> </array> </dict> </plist>

In short, this plist file tells the OS to run the identified script (~Library/Scripts/droid-sync) when the specified WatchPath changes.

The sync script itself lives in ~Library/Scrips and consists of a check against the desired volume (here’s where naming the Droid SD card comes in) and an rsync of the designated published collection to the previously-generated target directory on the SD card.

#!/bin/bash # delay a short time to make sure the path is available echo -n "[*]-- new /Volumes... sleeping" | logger sleep 20 if [ ! -e "/Volumes/DROIDX" ]; then       echo -n "[*]-- DROIDX NOT connected - Exiting" | logger       exit 0    else       echo -n "[*]-- DROIDX Connected - Performing gallery sync" | logger fi # rsync with delete option rsync --delete -r ~/Pictures/Exported\ Photos/Droid/ /Volumes/DROIDX/Galleries echo -n "[*]-- DROIDX gallery sync complete" | logger

Finally, tell the LaunchAgent controller to watch your scripts by doing the following at a terminal:

  • launchctl load ~/Library/LaunchAgents
  • launchctl list | grep sync

You should see your droid-sync script appear in the list produced by the second command, above.

Now you’re ready!

Plug in and go

That really should do it. When you connect the Droid X, you can watch the messages in the sync script appear in your console log, and everything should work — after syncing, disconnect the device again and fire up the gallery application; in the “Folders” section of the gallery you should see an item for each gallery you create in Lightroom. You’re done!

As with the iPad workflow, the great part of this is that once it’s set up, it’s pretty automatic. If you edit, add, or remove photos, as long as you republish the collection, those changes will all be pushed over to the Droid. Thanks to a little nerdery and Lightroom, we’ve built a bit of functionality that the Droid software doesn’t directly offer — and it’s still done with LR as the core of the photo library.