Quickly Sync JPG mtime with EXIF CreateDate

I borrowed a few things, made a few changes, and now all my photos have the correct timestamp on the filesystem. Hooray!

The script expects to be in the root directory of the album hierarchy, but that is merely because I am lazy. And it was an excuse to learn about how to find where a bash script lives. Also, a refresher handling spaces in paths in bash using read.

Finally, exiftool is awesome! (perl-Image-ExifTool on Fedora 16.)

#!/bin/bash
 
#
# Script to sync the filesystem date with that from EXIF CreateDate field.
#
 
set -e
 
# http://hintsforums.macworld.com/showpost.php?p=523850&postcount=20
self="$(cd "${0%/*}" 2>/dev/null; echo "$PWD"/"${0##*/}")"
 
# http://www.perlmonks.org/?node_id=767176
find $(dirname $self) -name '*.jpg' -print0 | while read -d $'\0' f
do
  exiftool -S -d "%Y%m%d%H%M.%S" -CreateDate "${f}" \
  | awk '{ print $2 }' \
  | xargs -I % touch -m -t % "${f}"
done

Post a Comment

Your email is never shared. Required fields are marked *

*
*