I know this is old and answered, but I think the script I put together after a day of googling and trying is worth sharing.
Modify your options, and this script either moves or copies your originals to a folder named 'yyyy-mm-dd Your Album Name'. So you keep track of your original album titles, and all photos are sorted by day as well.
Modify to suit your needs.. I do this to be able to have a shared file base of original photos synced by dropbox, and all sharing users can have their own copy of Photos.app use that as a base for referenced photos.
It attempts to avoid overwriting photos with the same name, by first verifying if a non-identical file exists at the same path already.
Also, it sets the timestamp of the newly made folders to the date of the events they have. Nice to sort events by date in finder or whatever, although the folder names already start with the date (because if you copy them elsewhere, timestamps may change anyway).
It is compatible with single quotes in album names. It may be compatible with quotation marks, but I have NOT tested that.
#!/bin/bash
#### A few options ####
#dryrun=1
dryrun=0
# Choose to duplicate (slow, space eating) or move (space saving, fast if on same drive).
#action=cp
action=mv
# set your paths
# origin:
libr="Photos Library.photoslibrary"
# destination:
destpath="MyProperlyOrganizedFotos"
# no idea why Apple chooses a funny date. Adjust to your time-zone needs
dateoffset=978307200
#### End of options ####
sqllib="${libr}"/Database/apdb/Library.apdb
s="sqlite3 ${sqllib}"
#${s} 'select fileName,imageDate,imagePath,projectUuid from RKMaster'
${s} 'select fileName,imageDate,imagePath,projectUuid from RKMaster' | sed 's,",thisisaquotationmark,g' | while read -r line; do
echo $line
name=`echo "$line" | awk 'BEGIN {FS="|"} {print $1}'`
date=`echo "$line" | awk 'BEGIN {FS="|"} {print $2}'`
path=`echo "$line" | awk 'BEGIN {FS="|"} {print $3}'`
albumid=`echo "$line" | awk 'BEGIN {FS="|"} {print $4}'`
albumname=`${s} "select name from RKFolder where uuid == '${albumid}'" | sed -e 's,/,:,g' -e 's,!,,g' -e 's,",thisisaquotationmark,g'`
realdate=`date -r $(( ${dateoffset} + ${date} )) '+%Y-%m-%d' `
touchdate=`date -r $(( ${dateoffset} + ${date} )) '+%Y%m%d1200' `
# does this file still exist? or did we move it already?
src=`echo ${libr}/Masters/${path} | sed 's/thisisaquotationmark/\\"/g'`
if [ ! -f "${src}" ]; then
continue
fi
# trim:
newpath=`echo $realdate $albumname | sed 's/thisisaquotationmark/\\\\"/g'`
if [ ! $dryrun -eq 1 ]; then
expandednewpath=`echo ${newpath}`
mkdir -p "${destpath}/${newpath}"
touch -t ${touchdate} "${destpath}/${newpath}"
fi
target="${destpath}/${newpath}/${name}"
index=0
# add an integer index to a file if the name exists in this path already
while [ -f "${target}" ] && ! cmp --silent "${target}" "${src}" ; do
echo 'Avoiding overwrite: ' $index
index=$(( $index + 1 ))
target="${destpath}/${newpath}/${name} $index"
done
if [ $dryrun -eq 1 ]; then
echo "Would do ${action} '${src}' '${target}' "
else
echo "${action} '${src}' '${target}' "
${action} "${src}" "${target}"
fi
done