MacOS – how to do a batch change (shift) of file creation date

filemacos

OS X Yosemite:

I took thousands of pictures on a trip recently, some from my iPhone, and some from my DSLR camera.

Now, the iPhone automatically gets its time and date from the local cell towers, but the DSLR stayed set with the time and date of its original configuration.

So basically now when I mix all the photos together and sort them by time and date, they are all out of order. I would like to view the photos chronologically and to do that I need to shift the date and time of all the DSLR photos by the same (time zone) offset.

So basically, I need a command line or a script that will do something like this:

if filename = DSC_*.*
then creation_date = creation_date + 5 hours

I'm asking this for OS X specifically, but I guess it would be interesting to know how to do this in Windows or Linux as well.

Best Answer

Here is a condensed and modified version of the script info in the link I gave you in the comments. You can save it as a plain text file, without an extension, and make it executable per info in the link, e.g. chmod +x filename. Place the script in a folder that's in your $PATH e.g.: /usr/local/bin/

This script sets both the created and modified date/time stamp on each DSC_*.* file +5 hours on the DSC_*.* files in the working directory.

In a Terminal then cd to the directory containing the DSC_*.* files and then type the name you gave to the script and press enter.

#!/bin/bash
for f in DSC_*.*; do
    ts="$(GetFileInfo -d "$f")"
    e="$(date -j -f "%m/%d/%Y %H:%M:%S" "$ts" +%s)"
    ((o=60*60*5))
    ((e+=o))
    nd="$(date -r $e "+%m/%d/%Y %H:%M:%S")"
    SetFile -m "$nd" "$f"
    SetFile -d "$nd" "$f"
done

In case the comment to the OP gets deleted the code above is based on the answer to Updating File Created Date by x number of days Mac OSX and modified to the +5 hours requested. If you only want to change the created time then comment out, placing a # in front of, or removing the SetFile -m "$nd" "$f" line.