Musical chairs with Headline, Title, Base Filename

General Discussion of Scripting for Adobe Bridge

Moderators: Tom, Kukurykus

aeryn

Musical chairs with Headline, Title, Base Filename

Post by aeryn »

It's very bad form to ask for help on my first post...but, trust me, you don't want me answering any questions at this point!
(My scripting knowledge is the ability to occasional reverse engineer an existing script to suit my needs, but it's just interchanging variables, I have no idea how to "read" what I'm writing.) So if anyone feels pity on a newbie, here's my request:

I want to, for selected files, copy IPTC Title to IPTC Headline. And a second script to, for selected files, write base filename (no extension) to IPTC Title. (Base filename is always 9 characters, extensions vary.)

Can anyone point/shove me in the right direction?

I found "Write Filename to IPTC Title Field" and it does 95% of what I need for the second script perfectly. I tried reverse engineering some code to strip the extension but ending up breaking it.

Thanks!
larsen67

Musical chairs with Headline, Title, Base Filename

Post by larsen67 »

Well, I had a quick look at this and it seams that Im unable to get this to work don't know if thats down to my bad coding or the version of CS that I have was not so good at this?
If I open the files in Photoshop then I have NO problems like so:
Code: Select all#target photoshop

bringToFront();

with (app) {
   for (var i = 0; i < documents.length; i++) {
      activeDocument = documents;
      docRef = activeDocument;
      docRef.info.headline = docRef.info.title
      docRef.close(SaveOptions.SAVECHANGES);
   }
   alert('Done');
}
ditto this…
Code: Select all#target photoshop

bringToFront();

with (app) {
   for (var i = 0; i < documents.length; i++) {
      activeDocument = documents;
      docRef = activeDocument;
      docRef.info.title = docRef.name.split('.')[0];
      docRef.close(SaveOptions.SAVECHANGES);
   }
   alert('Done');
}
They appear to do the job. However when I try in Bridge with:
Code: Select all#target bridge
 
with (app.document) {
   if (selections.length > 0) {
      for (var i = 0; i < selections.length; i++) {
         md = selections.synchronousMetadata;
         if (selections.type == 'file') {
            md.namespace = 'http://purl.org/dc/elements/1.1/';         
            var thumbName = selections.name.split('.')[0];
            //$.writeln(thumbName);
            md.title = thumbName; // Uncaught exception title
         } else {
            alert('This Selection is NOT a File!!!');
         }
      }
   } else {
      alert('You have nothing selected?');
   }
}
I get "Uncaught exception title"? Maybe Mike, X ,or Paul could explain this better as I can't understand this XMP at times?
Code: Select all#target bridge
 
with (app.document) {
   if (selections.length > 0) {
      for (var i = 0; i < selections.length; i++) {
         md = selections.synchronousMetadata;
         if (selections.type == 'file') {
            //md.namespace = 'http://purl.org/dc/elements/1.1/';         
            var thumbTitle = md.title;
            $.writeln(thumbTitle);
            md.headline = thumbTitle; // Uncaught exception headline
         } else {
            alert('This Selection is NOT a File!!!');
         }
      }
   } else {
      alert('You have nothing selected?');
   }
}
This too I get "Uncaught exception headline"? Is this because XMP metadata was rubbishy handled in CS2 and thats why CS4+ has that library thing I can't use? Im thinking it has something to do with properties being 'bag' or whatever and belonging to more than one namespace? Im sure you will be shown a better way as soon as someone with more up to date software pops along… Commenting out the namespace has NO influence either?
Mike Hale

Musical chairs with Headline, Title, Base Filename

Post by Mike Hale »

As I remember Bridge is limited to which XMP it can write to with the XMPLib that is only in newer versions.

Paul is better at Bridge scripts than I am so let's wait a few days for him to get back.
aeryn

Musical chairs with Headline, Title, Base Filename

Post by aeryn »

Is it okay if I don't quite understand all of what you said?

I've never used metadata-related scripts in PS, only in Bridge...is it much different? If batch processing is an option then I guess it wouldn't really matter which program I use. Thank you bunches for this first crack, it gives me something to play around with later.

As a side note: sounds like a government operation for the same script to work differently in family-related software.
Mike Hale

Musical chairs with Headline, Title, Base Filename

Post by Mike Hale »

I guess we should ask what version of Photoshop and Bridge are you using? If you have CS3 or higher then we can come up with a script for either Bridge or Photoshop that has full access to the metadata. It is just pre CS3 that is limited to what it can write.
aeryn

Musical chairs with Headline, Title, Base Filename

Post by aeryn »

I'm on CS4.
larsen67

Musical chairs with Headline, Title, Base Filename

Post by larsen67 »

Then you should be able to utilize the XMP library thing which I think is much more successful… I've NOT got that…
xbytor

Musical chairs with Headline, Title, Base Filename

Post by xbytor »

In xtools, I have a set of files for working with metadata in a variety of different ways.

XMPNameSpaces handles dealing with XMP namespaces.
XMPTools simplifies using the XMP lib. It's usable in various versions of PS and Bridge.
metadata.js will work with whatever you can give it: a Document, XMP as xml (but not using the XMP library), and XMP via the XMP library.
There is also some code in XBridgeTalk that calls Bridge from PS to get metadata. This is useful for versions of PS that don't support the XMP lib
and you need to access the metadata without opening the file in PS.

All of this may be overkill for your needs, but I've need to use each of these techniques at one time or another due to the capabilities of whatever
version of PS I was using; some of this will work in version of PS as far back as PSCS.

Here's some sample code:
Code: Select allXMPNameSpaces._test = function() {
  var props = ["iptcCore:City",
               "iptcCore:city",
               "Artist",
               "artist",
               "City",
               "tiff:Artist",
               "tiff:artist",
               "http://ns.adobe.com/exif/1.0/aux/Shutter",
               "exif:badProperty",
               "badProperty"
               ];

  var str = '';
  for (var i = 0; i < props.length; i++) {
    var p = props;
    var cname = XMPNameSpaces.getCanonicalName(p) || "[unknown]";
    str += p + " = " + cname + '\r';
  }
  alert(str);
};

XMPTools.test = function() {
  if (!XMPTools.isCompatible()) {
    Error.runtimeError(XMPTools.ERROR_CODE,
                       "This version of " + app.name +
                       " is not compatible with XMPScript.");
  }

  XMPTools.loadXMPScript();

//   var f = new File(Folder.desktop + '/test.psd');

//   var xf = new XMPFile(f.absoluteURI,
//                        XMPConst.UNKNOWN,
//                        XMPConst.OPEN_FOR_UPDATE);


//   var f = new XMPFile("/tmp/test.psd",
//   var f = new XMPFile("/Users/xbytor/Desktop/images/spaceball.gif",
//     XMPConst.UNKNOWN,
//     XMPConst.OPEN_FOR_UPDATE);

  try {
    var testFolder = new Folder(XMPTools.test.FOLDER);
    var images = Stdlib.getImageFiles(testFolder);

    var image = images[0];
    var image = new File(XMPTools.test.FOLDER + "/test.psd");
    var md = XMPTools.loadMetadata(image);

    //alert(md.getProperty(XMPConst.NS_PHOTOSHOP, "ColorMode").value);
    //alert(XMPTools.getMetadataValue(md, 'photoshop:ColorMode'));

    alert(XMPTools.getMetadataValue(md, 'crs:ToneCurve'));
    alert(XMPTools.getMetadataValue(md, 'photoshop:ColorMode'));
    alert(XMPTools.getMetadataValue(md, 'Description'));
    alert(XMPTools.getMetadataValue(md, 'exif:Flash'));
    alert(XMPTools.getMetadataValue(md, 'xmpMM:History'));

//     alert(md.serialize(XMPConst.SERIALIZE_OMIT_PACKET_WRAPPER | XMPConst.SERIALIZE_USE_COMPACT_FORMAT ));
//     alert(md.dumpObject());

  } catch (e) {
    alert(Stdlib.exceptionMessage(e));
  }

  XMPTools.unloadXMPScript();
};



Metadata.test = function() {
   var doc = app.activeDocument;
//   alert(new EXIF(doc).toString());
//   return;

  var md = new Metadata(doc);
  var tags = ["${EXIF:Exposure Time}",
              "${EXIF:GPS Latitude}",
              "${EXIF:ISO Speed Ratings}",
              "${IPTC:Author}"];
  var res = md.get(tags);

  alert(listProps(res));
};
Metadata.mdTest = function() {
  var doc = app.activeDocument;
  var md = new Metadata(doc);

  var str1 = "%d %p %f %F %e %s";
  alert(md.strf(str1));

  var str2 = "%T{%y-%m-%d} %N{%D} %W %H %R %B";
  alert(md.strf(str2));

  var str3 = "%X{xap:CreateDate} %I{Author} %X{dc:format}";
  alert(md.strf(str3));
};

Paul MR

Musical chairs with Headline, Title, Base Filename

Post by Paul MR »

Here are both scripts....
aeryn

Musical chairs with Headline, Title, Base Filename

Post by aeryn »

So, the "notify me by email" feature is very handy for forums...assuming you don't have spam controls set tougher than Fort Knox.

Thank you very much for the help, I'm working my way through the methods you have provided. I'll let you know what happens.


ETA: Paul...you, sir, are my hero! I tried your scripts first and they do exactly what I want. Thank you so much.

And thank you to everyone for giving me lots of script to play with and use for reverse engineering in the future.