Applescript: Read EXIF data and change "created date"

Discussion in 'Mac Programming' started by katanna, Apr 25, 2009.

  1. katanna macrumors 6502


    May 6, 2004
    Here's the deal. I have a bunch of photos that I have imported and exported out of iPhoto which changed their "created date" in the Finder. However, their "capture date" is still the same in the EXIF data. I would like a quick AppleScript application that will update all of the "created dates" to match the "capture date".

    I have found all of the AppleScript pieces, I just don't know any AppleScript to put them together.

    For example, I found this piece of code that will change a file's "created date", so I know it can be done in AppleScript:

    on open files_
    	display dialog "enter the new creation date in format YYYYMMDDhhmm ex: 200112251730:" default answer "" buttons {"Cancel", "Continue"}
    	copy the result as list to {the new_creation_date, the button_pressed}
    	repeat with file_ in files_
    		tell application "Finder"
    			set file_ to POSIX path of file_
    			do shell script "touch -t " & new_creation_date & " " & quoted form of file_
    		end tell
    	end repeat
    end open
    I also have iMagine Photo installed, which can read EXIF data into AppleScript. (Here is their first help page, which is I am sure all you will need.)

    I can tell AppleScript to read the EXIF data, and I can tell AppleScript to change a file's "creation date", I just don't know how to translate the information from one to the other. Can anyone help? Thanks a bunch!

  2. Fredzilla macrumors newbie

    Nov 4, 2009
    Did you ever get an answer to this? I'm trying to do the exact same thing.

  3. autorelease macrumors regular

    Oct 13, 2008
    Achewood, CA
    jhead is a Unix command line utility that can manipulate EXIF data. You can install it with MacPorts or download a prebuilt executable from the website. You can then call jhead from your AppleScript.
  4. katanna thread starter macrumors 6502


    May 6, 2004
    I found a program called ShootShifter:

    One of it's features is that it will automatically update the OS X info from the EXIF data. To fix the images, just make sure the program has the correct settings and import the photos into the program. It fixes everything! (Then just quit the program and go along your marry way.)

  5. NogbadTheBad macrumors regular


    Aug 28, 2009
    United Kingdom
  6. solesio, Feb 23, 2019
    Last edited: Mar 12, 2019

    solesio macrumors newbie


    Feb 23, 2019
    Hi Matthew

    I just had the same problem and I could solve it. Not perfectly, but well enough even though I am an applescript newbie.

    I could copy and paste several applescript fragments altoghether.
    This is the resulting code. It doesn't work properly some times (when the pictures have no EXIF information ) .BUT I DON'T KNOW HOW TO MAKE IT TO CONTINUE IN CASE THERE IS NO EXIF INFO IN A FILE. ANY HELP WOULD BE APRECIATED.

    This script will change de "creation date" shown in finder of every file in /Users/fran/Desktop/carpeta to the date saved on EXIF information of each file

    Hope it helps others! :)

    (Edited to filter only jpg files)

    tell application "Finder"
    set theFileList to (every file in entire contents of folder POSIX file "/Users/fran/Desktop/Carpeta/" whose name extension = "jpg") as alias list
    end tell
    repeat with theFile in theFileList
    tell application "Image Events"
    set theOpenFile to open theFile
    tell theOpenFile
    set theTag to metadata tag "creation"
    end tell
    set theTagValue to value of theTag
    close theOpenFile
    end tell
    set fileName to POSIX path of theFile
    -- display dialog fileName & return & theTagValue
    set theTagValue to do shell script "echo " & quoted form of theTagValue & ¬
    " | sed -e 's/://g'"
    set theTagValue to do shell script "echo " & quoted form of theTagValue & ¬
    " | sed -e 's/ //g'"
    set theTagValue to text 1 thru -3 of theTagValue & "." & text -2 thru end of theTagValue
    do shell script "touch -t " & theTagValue & " " & quoted form of fileName as POSIX file
    end repeat

Share This Page

5 April 25, 2009