Skip to content

Instantly share code, notes, and snippets.

@smartmic
Last active January 2, 2017 20:42
Show Gist options
  • Save smartmic/f8163ac643b44afbe399a8df81857b39 to your computer and use it in GitHub Desktop.
Save smartmic/f8163ac643b44afbe399a8df81857b39 to your computer and use it in GitHub Desktop.
Script to move files from iPhoto exports into appropriate subfolders
# iphoto2folders.sh
#
# Script to move files from iPhoto exports into appropriate subfolders
# (according file name prefix as chosen in iPhoto, here "Events".
#
# First, in iPhoto select all events and do Photos > Batch Change
# Set Title to Event Name
# With all events highlighted, export events a folder somewhere, for filename use title
# Photos will be exported with filename of "event - number.jpg" (ex: Animals - 0004.jpg)
#
# Set the iphoto_dir variable below to the full path of the directory
#
# Written by Martin Michel, Jan 2017
# (inspired by http://hints.macworld.com/article.php?story=20081108132735425)
shopt -s extglob
IFS=$'\n'
iphoto_dir='/home/martin/Public/Shared_Pictures/iPhoto_Export/'
cd $iphoto_dir
dirs=(`ls -1 | awk -F' - ' '{print $1}' | sort -u`)
for event in ${dirs[*]}
do
if [ ! -d $event ]
then mkdir $event
fi
for filename in $event*@(.jpg|.MOV|.AVI|.mp4|.mov)
do
mv $filename $event/`echo $filename | awk -F' - ' '{print $2}'`
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment