Created
January 27, 2021 17:08
-
-
Save ascarter/1083c6d1477405348976d4f23ee68154 to your computer and use it in GitHub Desktop.
Set missing date/time stamps in photos
This file contains hidden or 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/sh | |
# Set missing datetime tags | |
find "${1:-$PWD}" -not -name ".DS_Store" -type f | while read f | |
do | |
# Assumption that files came from Apple Photos export | |
# Organized: | |
# <month> <day>, <year> | |
d=$(basename "$(dirname "${f}")") | |
datestamp=$(echo "${d}" | sed -E 's/(^.+[,][[:space:]])?([[:alpha:]]+[[:space:]][[:digit:]]+[,][[:space:]][[:digit:]]+)/\2/g') | |
timestamp=$(date -j -f "%B %d, %Y" "$datestamp" "+%Y:%m:%d 00:00:00") | |
# Fix missing date tags | |
exiftool -overwrite_original_in_place -alldates="'$timestamp'" -if '(not $datetimeoriginal or not $createdate)' "${f}" | |
exiftool -f -filename -make -datetimeoriginal -subsectimeoriginal -offsettimeoriginal -subseccreatedate -filecreatedate -filemodifydate -createdate -modifydate "${f}" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment