Date Formatting query - Changing Creation date of Jpeg images.

Hi All,

I have a library of images from an old iPhoto database which all have the creation date of “1 Jan 1970”. which is incorrect (obviously!!) BUT the folder structure they’re indicates the date they were added to iPhoto. I have written a script to extract the folder names to a date string but i’m getting and error :

“Can’t make {“28”, “/”, “05”, “/”,“2011”} into type date” when trying to concatenate the variables. Some help please with date formatting.


set myJpeg to choose file
set AliasPath to the result as text

set tids to AppleScript's text item delimiters
set AppleScript's text item delimiters to ":"

-- Determine how many folders are in the path string
set fldrcount to the (count of text items) of AliasPath
-- display dialog fldrcount
set fldrcount to fldrcount as integer

-- Get Year date from alias
set YearFldr to (fldrcount - 3) as integer
set YearDate to text items YearFldr through -4 of AliasPath
-- display dialog YearDate as string

-- Get Month date from alias
set MnthFldr to (fldrcount - 2) as integer
set MnthDate to text items MnthFldr through -3 of AliasPath
-- display dialog MnthDate as string

-- Get Day date from alias
set DayFldr to (fldrcount - 1) as integer
set DayDate to text items DayFldr through -2 of AliasPath
-- display dialog DayDate as string

set AppleScript's text item delimiters to tids

set NewCreateDate to {DayDate & "/" & MnthDate & "/" & YearDate} as date  <- !! ERROR OCCURS HERE !!

display dialog NewCreateDate as string

tell application "Finder"
	set the creation date of myJpeg to NewCreateDate as date
	
end tell

SAMPLE REPLY FROM SCRIPT EDITOR:

tell application “Script Editor”
choose file
→ alias “Data:Projects:Development:Applescript:MacPro:iPhoto batch creation date:Sample images:2011:05:28:DSC01065.JPG”
Result:
error “Can’t make {"28", "/", "05", "/", "2011"} into type date.” number -1700 from {“28”, “/”, “05”, “/”, “2011”} to date

Thanks in Advance.

Model: MBP 2013 15"
AppleScript: 2.4
Browser: Safari 600.7.12
Operating System: Mac OS X (10.10)

Hi,

the reason for the error is that

text items YearFldr through -4 of AliasPath

returns a list instead of the expected string.

Your script can be simplified a bit

set myJpeg to (choose file) as text

set tids to text item delimiters
set text item delimiters to ":"

set {yr, mn, dy} to text items -4 thru -2 of myJpeg
set AppleScript's text item delimiters to "/"
set NewCreateDate to date ({dy, mn, yr} as text)
set text item delimiters to tids

display dialog NewCreateDate as string

tell application "Finder"
	set the creation date of file myJpeg to NewCreateDate
end tell

but the real bad news is that you can’t set the creation date with the Finder.
You need SetFile from the developer tools or other third party tools.

There’s a CLI utility called jhead.
One of the things it can do is rename files with their EXIF shoot date.
If the EXIF data in your photos are OK you could use that.
You can use Preview to take a peek.