Last active
February 28, 2020 01:14
-
-
Save paunin/e4f9f01a1cfcfc99828b75d4fd29ac96 to your computer and use it in GitHub Desktop.
Organizing exported from *.photoslibrary pictures
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!env bash | |
#https://gist.github.com/paunin/e4f9f01a1cfcfc99828b75d4fd29ac96 | |
# Export files from apple *.photoslibrary (File->Export Unmodified Original) with options "Subfolder Format = Moment Name" | |
# Run the script against the folder where the images were exported. | |
# Subfolders will be renamed from format `{MOMENT_NAME}, d Month YYYY` to `YYYY.mm.dd[{MOMENT_NAME}]` | |
# example: `Da Lat - Phường 8 - Tỉnh Lâm Đồng, 3 May 2016` => 2016.05.03[Da Lat - Phường 8 - Tỉnh Lâm Đồng] | |
DIR=$1 | |
if [[ "$DIR" == "" ]]; then | |
echo "Error: please pass \$1 for directory to organize! " | |
exit 1 | |
fi | |
echo "Organizing '$DIR'..." | |
ls $DIR > source.txt | |
while read -r SOURCE; do | |
DEST=`echo $SOURCE | \ | |
sed -e 's/ January /.01./g' \ | |
-e 's/ February /.02./g' \ | |
-e 's/ March /.03./g' \ | |
-e 's/ April /.04./g' \ | |
-e 's/ May /.05./g' \ | |
-e 's/ June /.06./g' \ | |
-e 's/ July /.07./g' \ | |
-e 's/ August /.08./g' \ | |
-e 's/ September /.09./g' \ | |
-e 's/ October /.10./g' \ | |
-e 's/ November /.11./g' \ | |
-e 's/ December /.12./g' \ | |
\ | |
-e 's/\(.*\),\ \([0-9]\{1,2\}\.[0-9]\{2\}\.[0-9]\{4\}\)/\2[\1]/g' \ | |
-e 's/^\([0-9]\{1\}\.\)/0\1/g' \ | |
-e 's/\([0-9]\{2\}\)\.\([0-9]\{2\}\)\.\([0-9]\{4\}\)/\3.\2.\1/g' | |
` | |
# here ^ 4 steps: | |
# 1. Replace month names with number (January => .01.; February => .02.) | |
# 2. Moving Date to the begining of the name and put moment_name into breakets | |
# 3. Adding leading zero to the `day` part of the date | |
# 4. Changing date format from dd.mm.yyyy to yyyy.mm.dd | |
echo ">>> Moving '$SOURCE' ---> '$DEST'" | |
mv "$DIR/$SOURCE" "$DIR/$DEST" | |
done < source.txt | |
rm source.txt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment