Moving iPhone Photos with AutoImporter, ExifTool, Bash, & Applescript

I used to lug around a big DSLR camera before I started traveling more often and before I decided packing light was a skill I had to conquer. Flexible and creative packing is the reason my little iPhone camera turned in to my favorite snapshot tool and most of my photography shifted from stock and portraits to being just about capturing my own favorite memories. Every so often, I still get my hands on a nicer-than-nice, borrowed, gorgeous Nikon—which is pretty awesome because I can get a real photography fix without spending too much cash on equipment.

When it comes to photos just for me though, I love the iPhone camera so much. It’s freedom. It’s versatile. It does just enough. However, I was missing a way to organize photos into the folders I wanted exactly how I wanted them organized.

I use Lightroom, and I know it has an import feature, but I want the raw photo data where I put it, organized how I want it, and backed up the way I decide. Okay, so it’s about control, but it’s also about keeping my photo workflow the way I like it and the way I’ve always done it. Also, I really like bash scripts.


I organize my photos by date like this:


Then I use a setup like so to move photos:

  1. Make sure ExifTool is installed and working
  2. Set up a folder named ~/Pictures/Imported
  3. Connect your iPhone and open Image Capture
  4. For the “Connecting this iPhone opens” setting, select
  5. Open Finder, press Cmd+G and go to /System/Library/Image Capture/Support/Application/
  6. Double click and open Preferences right away
  7. For the “Import folder” setting, select ~/Pictures/Imported
  8. Uncheck the subfolder option
  9. Check the option to “Delete items from camera after successful import”
  10. Create a bash script ~/bin/ (see code below)
  11. Open AppleScript Editor and compile this line: do shell script "/Users/yourusername/bin/”
  12. Save the AppleScript as ~/Library/Scripts/Folder Action Scripts/movephotos.scpt
  13. Open Finder, right-click ~/Pictures/Imported, and go to Services > Folder Actions Setup…
  14. Select “movephotos.scrpt,” check “Enable Folder Actions,” and click the Attach button

~/bin/ sample code:

if [ -d $DEST_DIR ]; then
	for i in $( find $SOURCE_DIR -type f ) ; do
		mkdir -p $(exiftool -d $DEST_DIR/%Y/%m/%y%m%d/ -p '$DateTimeOriginal' $i);
		mv -n $i $_;

If you want to change file locations, just adjust the source and destination variables and the paths in the bash script to your liking.

Not everyone will like this setup. :) It’s pretty manual in some respects, but I like it because it lets me mess around with ExifTool and bash scripting and I can organize my photos exactly how I like.

[UPDATE: 2015-04-03 Based on Common Mistakes when using ExifTool, I was able to reduce the bash script above to a single line shown below. The path after “-d” is the target and the next path listed is the source.]

exiftool '-Directory
  • December 31, 2013 at 12:21 pm Lonnie Olson

    Tiny script suggestion. Getting the date from exiftool is enough, you don’t need to do it again using stat. Use a variable to save the folder location and use it both times.

    Inside your loop:
    DIR=$DEST_DIR/$(exiftool -d %Y/%m/%y%m%d/ -p ‘$DateTimeOriginal’ $i);
    mkdir -p $DIR
    mv -n $i $DIR

    Also, FYI: stat can be used to output any format you want, don’t need to use awk and sed to mangle it to your needs. See `man stat` for info about “Formats”.


    stat -f %Sm -t %Y/%m/%y%m%d

  • January 1, 2014 at 11:58 am Sheri Bigelow

    Ohhh. Thanks! I took it one step further and changed “mv -n $i $DEST_DIR/$(stat -t %Y/%m/%y%m%d $i | awk '{print $12}' | sed s/\"//g )/” to “mv -n $i $_“.

  • Mentioned in manually manage iOS photos on your Mac | /home/kOoLiNuS

  • Mentioned in Planet Automattic: February 2014 — Blog —

  • November 9, 2014 at 10:18 am Michael Rommel

    Hi Sheri,
    I made some alterations to let the script deal gracefully, with:
    a) spaces in the filename
    b) when no exif information is available (it uses the current date)
    Please note, that the described way for Automation Setup is now being replaced by Workflows in the Automator (
    My script looks like that:

    #!/bin/bash -x
    TODAY=$(date +”%Y/%Y-%m-%d”)

    make_and_move() {
    local i=”$1″
    FOLDERNAME=$(/usr/local/bin/exiftool -d “%Y/%Y-%m-%d/” -p ‘$DateTimeOriginal’ “$i”)
    if [ -z $FOLDERNAME ]; then
    mkdir -p $DEST_DIR/$FOLDERNAME
    mv -n “$i” “$DEST_DIR/$FOLDERNAME/”

    if [ -d $DEST_DIR ]; then
    find $SOURCE_DIR -type f -print0 | while read -d $” -r i ; do
    make_and_move “$i”

    Thanks for the inspiration!