Skip to content

Instantly share code, notes, and snippets.

@ascarter
Created January 27, 2021 17:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ascarter/1083c6d1477405348976d4f23ee68154 to your computer and use it in GitHub Desktop.
Save ascarter/1083c6d1477405348976d4f23ee68154 to your computer and use it in GitHub Desktop.
Set missing date/time stamps in photos
#!/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