Musical chairs with Headline, Title, Base Filename

General Discussion of Scripting for Adobe Bridge

Moderator: PS-Moderators

Musical chairs with Headline, Title, Base Filename

Postby aeryn » Wed May 19, 2010 5:07 pm

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! :shock:
(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!
aeryn
 
Posts: 4
Joined: Wed May 19, 2010 4:24 pm

Re: Musical chairs with Headline, Title, Base Filename

Postby larsen67 » Sat May 22, 2010 10:52 am

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[i];
      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[i];
      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[i].synchronousMetadata;
         if (selections[i].type == 'file') {
            md.namespace = 'http://purl.org/dc/elements/1.1/';         
            var thumbName = selections[i].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[i].synchronousMetadata;
         if (selections[i].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?
larsen67
 
Posts: 162
Joined: Sat Apr 25, 2009 3:01 pm
Location: Pickmere, Cheshire UK

Re: Musical chairs with Headline, Title, Base Filename

Postby Mike Hale » Sat May 22, 2010 2:38 pm

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.
Mike Hale
Site Admin
 
Posts: 2794
Joined: Fri Sep 30, 2005 10:52 pm
Location: USA

Re: Musical chairs with Headline, Title, Base Filename

Postby aeryn » Sat May 22, 2010 8:51 pm

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

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.
aeryn
 
Posts: 4
Joined: Wed May 19, 2010 4:24 pm

Re: Musical chairs with Headline, Title, Base Filename

Postby Mike Hale » Sat May 22, 2010 9:21 pm

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.
Mike Hale
Site Admin
 
Posts: 2794
Joined: Fri Sep 30, 2005 10:52 pm
Location: USA

Re: Musical chairs with Headline, Title, Base Filename

Postby aeryn » Sun May 23, 2010 2:46 pm

I'm on CS4.
aeryn
 
Posts: 4
Joined: Wed May 19, 2010 4:24 pm

Re: Musical chairs with Headline, Title, Base Filename

Postby larsen67 » Sun May 23, 2010 3:21 pm

Then you should be able to utilize the XMP library thing which I think is much more successful… I've NOT got that… :oops:
larsen67
 
Posts: 162
Joined: Sat Apr 25, 2009 3:01 pm
Location: Pickmere, Cheshire UK

Re: Musical chairs with Headline, Title, Base Filename

Postby xbytor » Sun May 23, 2010 7:26 pm

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 all
XMPNameSpaces._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[i];
    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));
};

for photoshop scripting solutions of all sorts
contact: xbytor@gmail.com
xbytor
Site Admin
 
Posts: 1986
Joined: Thu May 19, 2005 12:11 pm
Location: In Limbo

Re: Musical chairs with Headline, Title, Base Filename

Postby Paul MR » Wed Jun 23, 2010 8:44 pm

Here are both scripts....
Attachments
both scripts .zip
Filename to Title/Move Title to Headline
(1.77 KiB) Downloaded 9 times
Paul MR
 
Posts: 724
Joined: Wed Oct 18, 2006 2:44 pm
Location: Bradford,UK

Re: Musical chairs with Headline, Title, Base Filename

Postby aeryn » Thu Jul 01, 2010 11:06 pm

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. :mrgreen:
aeryn
 
Posts: 4
Joined: Wed May 19, 2010 4:24 pm


Return to Adobe Bridge Scripting: General Discussion

Who is online

Users browsing this forum: No registered users and 1 guest