Site Navigation


Currently:
Batch updating modification date to match EXIF

Posted on Tuesday 3 April 2007

While importing some old photo’s from a backup of my old gallery into iPhoto, I found out this program uses file modification dates instead of EXIF for organizing my photo’s (boo, Apple!). Not wanting to spend hours scouring the web in search of some crappy application with a GUI that’s hard to understand, I whipped up this simple Shell script to do it for me:

#!/bin/sh
# Simple script to adjust file modification dates to EXIF dates
# Michel Jansen 2007
# http://micheljansen.org
# Licensed under CC Attribution 3.0 unporded
# http://creativecommons.org/licenses/by/3.0/

errorOccured=0;

if [ $# -eq 0 ]; then 
	echo;
	echo "  Usage:" `basename $0` "“;
	echo ”  For example:” `basename $0` “~/pictures/*.jpg”;
	echo;
	errorOccured=1;
	exit 1;
fi

while [ -n “$1″ ]; do
	date=`jhead “$1″ | grep ‘Date/Time’ | sed -e “s/^[^:]*: *([^:]*):([^:]*):([^ ]*) ([^:]*):([^:]*):([^:]*)/12345.6/”` ;
	echo -n “Setting date of ”$1” to $date…”;
	if  `touch -cmt $date “$1″` ; then
		echo “OK”;
	else
		echo “ERROR”;
		errorOccured=1;
	fi
	shift;
done

exit $errorOccured;

It requires jhead and simply loops through all the files provided on the commandline, setting their last modified time to the one it reads from the picture’s EXIF data.


  • Bookmark using:

1 Comment for 'Batch updating modification date to match EXIF'

  1.  
    3 April, 2007 | 23:09
     

    Of course I only found out about jhead’s “-ft” option AFTER I wrote this script. Ah well, it may be useful for some purpose anyway :)

Leave a comment

(required)

(required)


Information for comment users
Line and paragraph breaks are implemented automatically. Your e-mail address is never displayed. Please consider what you're posting.

Use the buttons below to customise your comment.


RSS feed for comments on this post | TrackBack URI