Code: Select all
new XMPFile()
Do I need to test for sidecar files and parse those? I can't find documentation or anything online about this specific problem.
Code: Select all
this.run = JPEGExport();
function JPEGExport(){
var thumbs = app.document.getSelection("psd, jpg, png, tif, gif, CR2, nef");
if(thumbs.length != 0){
if (ExternalObject.AdobeXMPScript == undefined) ExternalObject.AdobeXMPScript = new ExternalObject("lib:AdobeXMPScript");
for(var i = 0;i < thumbs.length;i++){
if(thumbs[i].spec instanceof File){
var thumb = thumbs[i];
var selectedFile = thumb.spec;
var oldXmpFile = new XMPFile(selectedFile.fsName, XMPConst.UNKNOWN, XMPConst.OPEN_FOR_READ);
var oldXmp = oldXmpFile.getXMP();
var bm = new BitmapData(thumbs[i].spec);
if(bm instanceof BitmapData){
var fullName = thumbs[i].name;
var finalDotPosition = fullName.lastIndexOf(".");
if(finalDotPosition > -1){
repname = fullName.substr(0 , finalDotPosition);
}
}
var exportFilePath = thumbs[i].parent.spec + "/" + repname +"_new.jpg";
var exfile = new File(exportFilePath);
bm.exportTo(exfile);
var newthumb = exfile.spec;
var myXmpFile = new XMPFile(exfile.fsName, XMPConst.UNKNOWN, XMPConst.OPEN_FOR_UPDATE);
if (myXmpFile.canPutXMP(oldXmp)){
myXmpFile.putXMP(oldXmp);
myXmpFile.closeFile(XMPConst.CLOSE_UPDATE_SAFELY);
}
}
}
}
}