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.
- An API key from Google’s Developer Console
- Hazel (ideal, but costs money) or Folder Actions (free, but less reliable)
- terminal-notifier (if you don’t install this via Homebrew, you will need to change the path in the script)
- 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 below
5. Paste in the script found below (modifying the cities if necessary)
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/script.sh.