Last active
December 21, 2015 19:20
-
-
Save julienroubieu/6353921 to your computer and use it in GitHub Desktop.
Automator shell step.
Receives a list of photo files, extract the date from their name, set the date as EXIF tag, move the file to a directory named after the date, and pass it to the next step.
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
#!/bin/bash | |
dossier_ok=~/Desktop/Importes | |
for filepath in "$@" | |
do | |
((n++)) | |
filename=$(basename $filepath) | |
IFS='_' read -a array <<< "$filename" | |
year=${array[0]} | |
if ! [[ $year =~ [0-9]{4} ]] ; then continue; fi # Annee incorrecte | |
month=${array[1]} | |
if ! [[ $month =~ [0-9]{2} ]] ; then continue; fi # Mois incorrect | |
day=${array[2]} | |
if ! [[ $day =~ [0-9]{2} ]] ; then continue; fi # Jour incorrect | |
#echo "Processing ${filename}..." | |
exiftool -q −overwrite_original_in_place "-CreateDate=${year}:${month}:${day} 10:00:${n}" "${filepath}" | |
exiftool -q −overwrite_original_in_place "-DateTimeOriginal=${year}:${month}:${day} 10:00:${n}" "${filepath}" | |
# Create the folder | |
ok_dir="${dossier_ok}/${year}/${month}" | |
mkdir -p $ok_dir | |
# Move the file | |
dest="${ok_dir}/${filename}" | |
#echo "cp \"${filepath}\" \"${dest}\"" | |
mv "${filepath}" "${dest}" | |
echo $dest | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment