Skip to main content
Known Participant
January 19, 2011
Question

Script to transform portion of titles into EXIF Date Created? (CS5)

  • January 19, 2011
  • 1 reply
  • 954 views

Hi, folks--

Does anyone, by chance, have a script to take a portion of the title of my images and rewrite that in my EXIF Date Created section?

For example, I have a file named 20080603_211330_614012_2838b where the first two sections of numbers represent YYYYMMDD_HHMMSS.  I'd like the script to take that value and overwrite the existing Date Created data in the corresponding EXIF.

I know I can do this one image at a time using ExifToolGUI, but I'm looking for a script to batch out a couple thousand of these at a time.

Any help would be appreciated.

Thanks!

-Greg

This topic has been closed for replies.

1 reply

Paul Riggott
Inspiring
January 19, 2011

Please try this Greg, it works on selected files and the command is at the bottom of the Right Mouse Click Menu....


#target bridge  
   if( BridgeTalk.appName == "bridge" ) { 
exifDate = MenuElement.create("command", "EXIF Date from Filename", "at the end of Thumbnail");
}
exifDate.onSelect = function () {
   dateRename();
   }

function dateRename(){
var thumbs = app.document.selections;
if(!thumbs.length) return;
if (ExternalObject.AdobeXMPScript == undefined)  ExternalObject.AdobeXMPScript = new ExternalObject("lib:AdobeXMPScript");
for(var a =0;a<thumbs.length;a++){
    if(thumbs.type != "file") return;
var selectedFile = thumbs
.spec;   
var myXmpFile = new XMPFile( selectedFile.fsName, XMPConst.UNKNOWN, XMPConst.OPEN_FOR_UPDATE); 
var myXmp = myXmpFile.getXMP();
var nN =  decodeURI(thumbs
.spec.name).match(/^\d+_\d+/).toString();
var yyyy = nN.substr(0, 4);
var mm = nN.substr(4, 2);
var dd  = nN.substr(6, 2);
var th = nN.substr(9,2);
var tm = nN.substr(11,2);
var ts = nN.substr(13,2);
var newDate = mm +"-" + dd +"-" + yyyy+"T"+th+":"+tm+":"+ts;
var d = new XMPDateTime(new Date(newDate));
myXmp.setProperty(XMPConst.NS_PHOTOSHOP, "DateCreated", d, XMPConst.XMPDATE);
if (myXmpFile.canPutXMP(myXmp)) {
        myXmpFile.putXMP(myXmp);
         myXmpFile.closeFile(XMPConst.CLOSE_UPDATE_SAFELY);
         }
    }
}

Anon1066Author
Known Participant
January 19, 2011

Paul, I love it--thank you.

One more question: Can this script be amended to do the same function but for the "Date Modified" field?  In other words, take the numerical sequence from the title and translate it to "Date Modified" rather than "Date Created"?

-Greg

Paul Riggott
Inspiring
January 20, 2011

Yes, this will update the xmp modified field, allthough it will not change the FILE modified date, hope this ok.


#target bridge  
   if( BridgeTalk.appName == "bridge" ) { 
modDate = MenuElement.create("command", "Modified Date from Filename", "at the end of Thumbnail");
}
modDate.onSelect = function () {
   modEXIF();
   }
function modEXIF(){
var thumbs = app.document.selections;
if(!thumbs.length) return;
if (ExternalObject.AdobeXMPScript == undefined)  ExternalObject.AdobeXMPScript = new ExternalObject("lib:AdobeXMPScript");
for(var a =0;a<thumbs.length;a++){
    if(thumbs.type != "file") return;
var selectedFile = thumbs
.spec;   
var myXmpFile = new XMPFile( selectedFile.fsName, XMPConst.UNKNOWN, XMPConst.OPEN_FOR_UPDATE); 
var myXmp = myXmpFile.getXMP();
var nN =  decodeURI(thumbs
.spec.name).match(/^\d+_\d+/).toString();
var yyyy = nN.substr(0, 4);
var mm = nN.substr(4, 2);
var dd  = nN.substr(6, 2);
var th = nN.substr(9,2);
var tm = nN.substr(11,2);
var ts = nN.substr(13,2);
var newDate = mm +"-" + dd +"-" + yyyy+"T"+th+":"+tm+":"+ts;
var d = new XMPDateTime(new Date(newDate));
myXmp.setProperty(XMPConst.NS_XMP, "ModifyDate", d, XMPConst.XMPDATE);
if (myXmpFile.canPutXMP(myXmp)) {
        myXmpFile.putXMP(myXmp);
         myXmpFile.closeFile(XMPConst.CLOSE_UPDATE_SAFELY);
         }
    }
}