Getting EXIF data (actual creation date) from a JPEG

Hi there fellow AppleScripters,

I am trying to get the actual date/time digitised from a JPEG. I have tried three methods but they all give me the same incorrect answer, that being the file creation date/time. In some cases the file creation date is not the same as the date the photograph was taken.

Method 1: ask the Finder for the creation date
Method 2: ask Image Events to get the “creation” value.
Method 3: use the shell script “mdls” command to list all the metadata for the file

The interesting thing is that each method gives me the same date/time with different approaches to GMT.
Method 1: (finder creation date) gives me the file creation date/time adjusting for GMT in my region
Method 2: (Image Events) gives me the file creation date/time adjusting for GMT in the region that the image was saved.
Method 3: (Shell script ‘mdls’) gives me the file creation date/time without compensating for GMT

But that is just an interesting side note. The real puzzle is that if I open the JPEG in Preview and select Tools/Inspector and then click on the ‘EXIF’ tab, I am given the “Date Time Digitized” value which is the actual date/time the photo was taken and the same as the date stamp on the image itself. This is different from the file creation date/time.

My question is, does anyone know where the “date time digitized” information is stored in the JPEG and how it can be accessed using AppleScript and/or shell script?

Best regards,

Exiftool has always worked for me.

If you’re running Yosemite, this will give you a record with all the exif data:

use scripting additions
use framework "Foundation"
use framework "AppKit" -- for image stuff

set POSIXPath to POSIX path of (choose file of type {"jpg"})
my readEXIFFromJpeg:POSIXPath

on readEXIFFromJpeg:POSIXPath
	set theImageRep to current application's NSBitmapImageRep's imageRepWithContentsOfFile:POSIXPath
	set theEXIFData to theImageRep's valueForProperty:(current application's NSImageEXIFData)
	return theEXIFData as record
end readEXIFFromJpeg:
  -->	{DateTimeOriginal:"2015:04:30 17:15:53", MeteringMode:5, ComponentsConfiguration:{1, 2, 3, 0}, BrightnessValue:2.569557666779, FocalLenIn35mmFilm:29, LensMake:"Apple", FNumber:2.200000047684, FocalLength:4.150000095367, ShutterSpeedValue:4.907640457153, SubjectArea:{1631, 1223, 1795, 1077}, ApertureValue:2.275007247925, SceneType:1, SceneCaptureType:0, ColorSpace:1, LensSpecification:{4.150000095367, 4.150000095367, 2.200000047684, 2.200000047684}, PixelYDimension:3264, WhiteBalance:0, FlashPixVersion:{1, 0}, DateTimeDigitized:"2015:04:30 17:15:53", ISOSpeedRatings:{80}, ExposureMode:0, ExifVersion:{2, 2, 1}, PixelXDimension:2448, LensModel:"iPhone 6 back camera 4.15mm f/2.2", ExposureProgram:2, ExposureTime:0.033333335072, SubsecTimeDigitized:"258", Flash:24, SubsecTimeOriginal:"258", SensingMethod:2, ExposureBiasValue:0.0}

If you’re running Mavericks, you’ll have to save the handler in a script library.

Wow, nice script Shane. I don’t know if this is the same one that you posted before but it’s working great.


Thanks Shane and Craig, both your suggestions are very helpful!