Copy Rating from jpg to dng?

General Discussion of Scripting for Adobe Bridge

Moderators: xbytor, DavideBarranca, Paul MR

mrichter

Copy Rating from jpg to dng?

Postby mrichter » Mon Oct 04, 2010 7:16 am

Hi,
can someone help me?
My work colleague rated about 1000 files in Adobe Bridge. The problem is, that I have to use the *.dng version of the photos, not the jpgs. The dngs have the same filename (exept the file extension of course).
Is it possible to copy the Rating from the jpgs to the dngs?

thanks for your help!

(CS3)

larsen67

Copy Rating from jpg to dng?

Postby larsen67 » Wed Oct 06, 2010 11:54 am

Here is a link to a thread post over in the Photoshop scripting forum. Your request looks almost the same as what was wanted here. Take a look at Mike's last post in question to this. I would think matching up file name pairs to be straight forward enough to do.

http://forums.adobe.com/message/2923478#2923478

I don't have a version of CS that I can help you with but this should help you get started…

Paul MR

Copy Rating from jpg to dng?

Postby Paul MR » Wed Oct 06, 2010 3:24 pm

This should work, just run it from ESTK
Code: Select all#target bridge
app.bringToFront();
app.document.deselectAll();
var thumbs = app.document.getSelection("jpg");
for (var a in thumbs){
var Name = thumbs[a].spec.name.replace(/\.[^\.]+$/, '');
    var Rating='';
     var t = new Thumbnail(thumbs[a]);
     var md = t.synchronousMetadata;
      md.namespace = "http://ns.adobe.com/xap/1.0/";
      Rating = md.Rating;
      if(Rating == '') continue;
      var DNG = File(thumbs[a].spec.path + "/"+Name + ".dng");
      if(DNG.exists){
          var file = new Thumbnail (DNG);
          var md = file.synchronousMetadata;
      md.namespace = "http://ns.adobe.com/xap/1.0/";
      md.Rating = Rating;
          }
}

Jaybee

Copy Rating from jpg to dng?

Postby Jaybee » Thu Aug 11, 2011 10:49 am

Hi,

I'm looking for a way to extract the IPTC Keywords and IPTC Description fields from a jpg file in Bridge and write them to a PSD file that has the same filename.

The script above (top copy ratings across from a JPG to DNG version of the same file) seems exactly what I need except I want to copy just IPTC Keywords and Description fields from JPG to PSD for all matched pairs in a given folder.

I've modified the script to read "PSD" instead of DNG and that has worked for the ratings script above (successfully copying JPG ratings to the PSDs) but my knowledge of JS is pretty poor and I don't understand how I can reference the two IPTC fields I need copied over.

Using Bridge CS4.

Would be very grateful for any help. Thank you.

Jaybee

Quick update:

This script: bb/viewtopic.php?f=19&t=3433&p=15499&hi ... rds#p15499 has the functionality I'm after but requires manual intervention. If the Keywords & Description part of this script was merged with the script above I'm sure it would do exactly what I'm after.

Paul MR

Copy Rating from jpg to dng?

Postby Paul MR » Thu Aug 11, 2011 1:03 pm

Please try this...

Code: Select all#target bridge
app.bringToFront();
app.document.deselectAll();
var thumbs = app.document.getSelection("jpg");
for (var a in thumbs){
var Name = thumbs[a].spec.name.replace(/\.[^\.]+$/, '');
    var Rating='';
     var t = new Thumbnail(thumbs[a]);
     var md = t.synchronousMetadata;
      md.namespace = "http://purl.org/dc/elements/1.1/";
      var Desc = md.description;
      md.namespace = "http://ns.adobe.com/photoshop/1.0/";
      var Keys = md.Keywords;
      var PSD = File(thumbs[a].spec.path + "/"+Name + ".psd");
      if(PSD.exists){
          var file = new Thumbnail (PSD);
          var md = file.synchronousMetadata;
      md.namespace = "http://purl.org/dc/elements/1.1/";
      md.description = '';
      md.description= Desc.toString();
      md.namespace = "http://ns.adobe.com/photoshop/1.0/";
      md.Keywords = '';
      md.Keywords = Keys.toString();
          }
}

Jaybee

Copy Rating from jpg to dng?

Postby Jaybee » Thu Aug 11, 2011 1:09 pm

Hi Paul,

Thanks! That's working wonderfully for the IPTC Keywords part. I just ran it using the ESTK. All the JPG keywords in my test pairs transferred successfully to the PSD files in the same folder.

The IPTC Description field didn't come across though. Though I can see it referenced in your code...

Thanks for the quick reply too.

Jaybee

Paul MR

Copy Rating from jpg to dng?

Postby Paul MR » Thu Aug 11, 2011 1:31 pm

This should be better...

Code: Select all#target bridge
app.bringToFront();
app.document.deselectAll();
var thumbs = app.document.getSelection("jpg");
if (ExternalObject.AdobeXMPScript == undefined) ExternalObject.AdobeXMPScript = new ExternalObject("lib:AdobeXMPScript");
for (var a in thumbs){
var Name = thumbs[a].spec.name.replace(/\.[^\.]+$/, '');
    var Rating='';
     var t = new Thumbnail(thumbs[a]);
     var md = t.synchronousMetadata;
      md.namespace = "http://purl.org/dc/elements/1.1/";
      var Desc = "'"+ md.description+"'";
      md.namespace = "http://ns.adobe.com/photoshop/1.0/";
      var Keys = md.Keywords;
      var PSD = File(thumbs[a].spec.path + "/"+Name + ".psd");
      if(PSD.exists){
try{
var thumb = new Thumbnail(PSD);
var selectedFile = thumb.spec;   
var myXmpFile = new XMPFile( selectedFile.fsName, XMPConst.UNKNOWN, XMPConst.OPEN_FOR_UPDATE);
var myXmp = myXmpFile.getXMP();
if(Desc != '""'){
myXmp.deleteProperty(XMPConst.NS_DC, "description");
myXmp.setLocalizedText( XMPConst.NS_DC, "description", null, "x-default", Desc );
}
if(Keys.length >0){
myXmp.deleteProperty(XMPConst.NS_DC,'subject');
for(var s in Keys){
myXmp.appendArrayItem(XMPConst.NS_DC, "subject", Keys[s], 0,XMPConst.PROP_IS_ARRAY);
    }
}
if (myXmpFile.canPutXMP(myXmp)) {
        myXmpFile.putXMP(myXmp);
         myXmpFile.closeFile(XMPConst.CLOSE_UPDATE_SAFELY);
         }
     }catch(e){alert(e+ " occured at line : " + e.line);}
          }
}

Jaybee

Copy Rating from jpg to dng?

Postby Jaybee » Thu Aug 11, 2011 1:41 pm

Hi Paul,

99.9% success! Keywords 100% fine. Description field comes across but has a single quotation mark at either end. So:

Dog on beach transfers as 'Dog on beach'

Apart from that it's stellar!

Many thanks again.


Jaybee

Paul MR

Copy Rating from jpg to dng?

Postby Paul MR » Thu Aug 11, 2011 1:47 pm

Sorry about that, it's old age you know!

This should work now....

Code: Select all#target bridge
app.bringToFront();
app.document.deselectAll();
var thumbs = app.document.getSelection("jpg");
if (ExternalObject.AdobeXMPScript == undefined) ExternalObject.AdobeXMPScript = new ExternalObject("lib:AdobeXMPScript");
for (var a in thumbs){
var Name = thumbs[a].spec.name.replace(/\.[^\.]+$/, '');
    var Rating='';
     var t = new Thumbnail(thumbs[a]);
     var md = t.synchronousMetadata;
      md.namespace = "http://purl.org/dc/elements/1.1/";
      var Desc = "'"+ md.description+"'";
      if(Desc != "''") Desc = Desc.replace(/'/g,'');
      md.namespace = "http://ns.adobe.com/photoshop/1.0/";
      var Keys = md.Keywords;
      var PSD = File(thumbs[a].spec.path + "/"+Name + ".psd");
      if(PSD.exists){
try{
var thumb = new Thumbnail(PSD);
var selectedFile = thumb.spec;   
var myXmpFile = new XMPFile( selectedFile.fsName, XMPConst.UNKNOWN, XMPConst.OPEN_FOR_UPDATE);
var myXmp = myXmpFile.getXMP();
if(Desc != '""'){
myXmp.deleteProperty(XMPConst.NS_DC, "description");
myXmp.setLocalizedText( XMPConst.NS_DC, "description", null, "x-default", Desc );
}
if(Keys.length >0){
myXmp.deleteProperty(XMPConst.NS_DC,'subject');
for(var s in Keys){
myXmp.appendArrayItem(XMPConst.NS_DC, "subject", Keys[s], 0,XMPConst.PROP_IS_ARRAY);
    }
}
if (myXmpFile.canPutXMP(myXmp)) {
        myXmpFile.putXMP(myXmp);
         myXmpFile.closeFile(XMPConst.CLOSE_UPDATE_SAFELY);
         }
     }catch(e){alert(e+ " occured at line : " + e.line);}
          }
}

Jaybee

Copy Rating from jpg to dng?

Postby Jaybee » Thu Aug 11, 2011 1:53 pm

Thanks Paul

That's perfect! Just what I needed. Donation on it's way!

Cheers!

Jaybee


Return to “Adobe Bridge Scripting: General Discussion”

Who is online

Users browsing this forum: No registered users and 2 guests