Automatically Sort Dropbox Camera Uploads Based On Their Geographical Data

I have been a long time fan of using Dropbox to manage my photos, even with the release of Photos.  I have especially liked it ever since Dropbox enabled Camera Uploads from their iOS app.  With my latest script, I can now upload photos from my iPhone and have them automatically sorted into folders based on the city they were taken in.

To accomplish this, OS X’s Spotlight (mdls ) is used to extract the coordinates from the photo, and then those are sent to Google to get the city (or the state, address, and more).

For example, if I took a bunch of photos in New York City, as soon as they uploaded to Dropbox, they would be moved into ~/Dropbox/Pictures/New York City/ .  Or if I took some in Minneapolis, they would be uploaded to ~/Dropbox/Pictures/Minneapolis/ .  This could be taken a step further and the files could also be renamed, but for now I just like to have them organized instead of endlessly filling up my Camera Uploads folder.



  1. An API key from Google’s Developer Console
  2. Hazel (ideal, but costs money) or Folder Actions (free, but less reliable)
  3. terminal-notifier (if you don’t install this via Homebrew, you will need to change the path in the script)
  4. Modify the script to change the cities to ones where you take pictures

Getting An API Key

This is the hardest part because most people won’t have an API key and if you are not a developer, it might not make much sense.  The rest of the tutorial, you can basically copy/paste things and make a few modifications.

Just follow the instructions here to get one.  When asked about the key type, you can just choose browser.

The Hazel Workflow

First, drag and drop the Camera Uploads folder into the Hazel pane if it is not there already.

  1. Highlight the folder
  2. Click the plus icon on the right hand side of the pane
  3. Name the rule
  4. Change the values in the pull down menus as shown belowcreate-photo-sort-rule
  5. Paste in the script found below (modifying the cities if necessary)pasted scriptcompleted rule

The Script

This script needs to be run via Hazel after successfully matching a rule.  It will match the city name to the entries in the case  statement.  If a match isn’t found, nothing will happen.  In my case, I only visit a few select cities, so this works well.  If you wanted every photo to be sorted, you would need to come up with some more logic for the script.

Test It Out

If successful, as soon as a picture is added to your Camera Uploads folder, it will be moved and you will see the notification appear.


If you are having trouble, save the script as a file and test it manually before pasting it into the Hazel workflow.  You can see when each line of the script gets executed by using bash -x .  In Terminal, just enter bash -x /path/to/ .

4 Replies to “Automatically Sort Dropbox Camera Uploads Based On Their Geographical Data”

  1. If we could actually sort based on date… Oh dear, wouldn’t that be heavenly… Right now, sorting by file date is as good as we can do, but if we could parse EXIF and have Hazel do it based on the actual date that the pics were taken, I’d be in heaven.

    1. I already do something very similar using exiftool or other similar command line tools. You would basically parse down the output of the command, similar to how I get the latitude and longitude, and then use a case statement.

      I do something similar to find the orientation of the picture, and if it is sideways or upside down, I use sips to rotate it. All of this using Hazel, of course.

    2. You can get the create date from the EXIF data like this:

      exiftool /path/to/picture.jpg | awk '/Create Date/ {print $4, $5}'

      Sometimes, there will be two entries, one with miliseconds, so to get just the first one:

      exiftool /path/to/picture.jpg | awk '/Create Date/ {print $4, $5}' | grep -v "."

      1. Interesting… Eventually, I’ll find the time between work and school to explore this further. I think that the perfect solution would be to grab the date (as you noted above) then to create directories based on the date, finally moving the pic into the directory. Hazel does that now, but not based on the exif date (I don’t recall if it’s file creation, or modified, that Hazel is able to access/use). Even in it’s current form it isn’t too bad, unless I go long periods in between photo downloads (via Dropbox, so let’s say you go a week or two without firing up the laptop, that is when the lack of exif by Hazel becomes a little more apparent).
        Thanks for that information though; I definitely want to look into it further!

Leave a Reply