Change file creation date to content created date using terminal

I have a lot of pictures with the wrong creation date and wrong modification date. There is however a third date, "content created" that is correct. user3439894 had this command line as an answer to Change file creation date to modification date using terminal

for f in *.[iI][mM][gG]; do m="$(GetFileInfo -m "$f")"; SetFile -m "$m" -d "$m" "$f"; done

Where GetFileInfo reads the modified date and rewrites the created date. Very useful and works great (after installing the command line tools) for a lot of my pictures that have the correct modification date, thanks. What I am looking for now, is a syntax for "content created" date that I could use?

Any help on this would be great.

Update: The easiest is probably to install EXIFTOOL. This simple command line in terminal did the job. To set “Date Created” to time from EXIF’s “DateTimeOriginal”: exiftool "-FileModifyDate<DateTimeOriginal" *

to move time by X hours ahead you can do: exiftool "-DateTimeOriginal-=1" *


Solution 1:

Using tools that are part of macOS, We start by getting the ContentCreationDate from the file and place it into a container ccd -

ccd=$(mdls -raw -n kMDItemContentCreationDate FILE)

Next, We format the ContentCreationDate string into a string usable by SetFile and place that into a container nct -

nct=$(date -f '%F %T %z' -j "$ccd" '+%D %T %z')

Finally, We use SetFile and set the FSCreationDate to the modified date/time string from ContentCreationDate -

SetFile -d "$nct" FILE

I'm assuming that you know how to place all of this into a loop for processing multiple files.

Note: Look into exiftool