Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

katanna

macrumors 6502
Original poster
May 6, 2004
345
41
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:

Code:
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!

Matthew
 

autorelease

macrumors regular
Oct 13, 2008
144
0
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.
 

katanna

macrumors 6502
Original poster
May 6, 2004
345
41
I found a program called ShootShifter:

http://www.maczentrisch.de/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.)

Matthew
 

solesio

macrumors newbie
Feb 23, 2019
1
0
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
 
Last edited:

desvarre

macrumors newbie
Feb 23, 2021
1
0
From online snippets I have created a script that is very close to what you need.

When started, it asks for a folder. In that folder it scans for all jpg files, extracts their "digitized date" form EXIF and replaces the "date modified" date with the "digitized date".

I'm using it to rewrite "date modified" on files imported from iPhone via Photos app.

Here is the script, just paste it into Script Editor:

--------------------------------

AppleScript:
-- script will ask for folder
set files_in_folder to 0
set image_files_in_folder to 0
set images_changed to 0
set images_skipped to {}
log "01"
try
    set progress description to "Processing Images..."
    set progress additional description to "Preparing to process."
    set progress completed steps to images_changed
    -- get files
    set this_folder to (choose folder with prompt "Pick the folder containing the images to process:") as string
    tell application "System Events"
        with timeout of 600 seconds
            set these_files to every file of folder this_folder whose name does not start with "."
            set files_in_folder to count of these_files
            set these_files to every file of folder this_folder whose name does not start with "." and (name extension is "jpeg" or name extension is "JPEG" or name extension is "jpg" or name extension is "JPG")
            set image_files_in_folder to count of these_files
        end timeout
    end tell
    
    -- Update the initial progress information
    set progress additional description to "Begin process"
    set progress total steps to (count of these_files)
    
    
    repeat with i from 1 to the count of these_files
        log "0x"
        set this_file to (item i of these_files as alias)
        set this_file_name to (name of (info for this_file))
        set progress additional description to "Processing file " & this_file_name
        set filePathAS to this_file as string
        set filePathSH to quoted form of the POSIX path of filePathAS
        set dateTimeOriginal to do shell script "/usr/local/bin/exiftool -d '%Y%m%d%H%M.%S' -DateTimeOriginal " & filePathSH
        if (dateTimeOriginal is "") then
            set images_skipped to images_skipped & (this_file_name & ", ")
        else
            set dateTimeOriginal to ((characters 35 through -1 of dateTimeOriginal) as string)
            do shell script "touch -t " & dateTimeOriginal & " " & filePathSH
            set images_changed to (images_changed + 1)
            set progress completed steps to images_changed
        end if
    end repeat
    display alert "Task completed! " & return & "Folder has " & files_in_folder & " files, of which " & image_files_in_folder & " image files. " & return & "Images processed: " & images_changed & return & "Images skipped: " & (count of images_skipped) & return & return & images_skipped
on error the error_message number the error_number
    display dialog "Error: " & the error_number & ". " & the error_message & "(No images changed: " & (count of images_changed) buttons {"OK"} default button 1
end try

-- Reset the progress information
set progress total steps to 0
set progress completed steps to 0
set progress description to ""
set progress additional description to ""



--function is never used:

on replaceText(someText, oldItem, newItem)
    (*
     replace all occurances of oldItem with newItem
          parameters -     someText [text]: the text containing the item(s) to change
                    oldItem [text, list of text]: the item to be replaced
                    newItem [text]: the item to replace with
          returns [text]:     the text with the item(s) replaced
     *)
    set {tempTID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, oldItem}
    try
        set {itemList, AppleScript's text item delimiters} to {text items of someText, newItem}
        set {someText, AppleScript's text item delimiters} to {itemList as text, tempTID}
    on error errorMessage number errorNumber -- oops
        set AppleScript's text item delimiters to tempTID
        error errorMessage number errorNumber -- pass it on
    end try
    
    return someText
end replaceText
 

adrianlondon

macrumors 603
Nov 28, 2013
5,521
8,336
Switzerland
This isn't something I need to run regularly enough to make creating a script worthwhile, but as I use the (brilliant and free) "exiftool" program anyway, this simple command will set the file modification date to the date the photo was taken. There are flags which can run recursively down directories too; the command below will simply do all files ending in .jpeg in the current directory.

exiftool '-DateTimeOriginal>FileModifyDate' *.jpeg

There are other cool things which can be done, such as setting the Comment field in Finder to the EXIF/IPTC title of the image.

exiftool '-MDItemFinderComment<title' *.jpeg
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.