Skip to main content
Known Participant
May 31, 2013
Question

Copy keywords into title field, keep in keywords field

  • May 31, 2013
  • 1 reply
  • 1260 views

I have this script that works in cs5, but it is not working in CS6- I am going to try to modify it to copy the keywords into the title field, but also drop the ";" and replace with a ","

First, I can't get CS6 to run this code, though. Where is it wrong? Thank you for any suggestions-

#target bridge  

if( BridgeTalk.appName == "bridge" ) { 

keysToDesc = MenuElement.create("command", "Keywords To Description", "at the end of Tools");

}

keysToDesc.onSelect = function () {

   keysToDesc();

   }

function keysToDesc(){

    function getArrayItems(ns, prop){

var arrItem=[];

var items = myXmp.countArrayItems(ns, prop);

   for(var i = 1;i <= items;i++){

     arrItem.push(myXmp.getArrayItem(ns, prop, i));

                }

return arrItem.toString();

}

if (ExternalObject.AdobeXMPScript == undefined) ExternalObject.AdobeXMPScript = new ExternalObject("lib:AdobeXMPScript");

var thumb = app.document.selections;

    for(var s in thumb){

if(thumb.hasMetadata){

        var selectedFile = thumb.spec;

  var myXmpFile = new XMPFile( selectedFile.fsName, XMPConst.UNKNOWN, XMPConst.OPEN_FOR_UPDATE);

  var myXmp = myXmpFile.getXMP();

        var Keywords = getArrayItems(XMPConst.NS_DC,'subject').replace(/,/g,';')

         myXmp.deleteProperty(XMPConst.NS_DC, "description");

        myXmp.setLocalizedText( XMPConst.NS_DC, "description", null, "x-default", Keywords );

    }

        if (myXmpFile.canPutXMP(myXmp)) {

        myXmpFile.putXMP(myXmp);

        myXmpFile.closeFile(XMPConst.CLOSE_UPDATE_SAFELY);

         } else {

  xmpFile.closeFile();

        }

    }

}

This topic has been closed for replies.

1 reply

Paul Riggott
Inspiring
June 1, 2013

This should do...

#target bridge  

if( BridgeTalk.appName == "bridge" ) { 

keysToTitle = MenuElement.create("command", "Keywords To Title", "at the end of Tools");

    }

keysToTitle.onSelect = function () {

var sels = app.document.selections;

for(var a in sels){

md =sels.synchronousMetadata;

md.namespace = "http://ns.adobe.com/photoshop/1.0/";

var Keys =  md.Keywords.toString();

md.namespace = "http://purl.org/dc/elements/1.1/";

md.title ='';

md.title = Keys;

    }

};


pwfasprodAuthor
Known Participant
June 1, 2013

On my mobile right now, thank you for that, I will try it soon! What are the links in there? Does it function like linking to web hosted jquery?

Paul Riggott
Inspiring
June 1, 2013

No, they are just the Schema's namespace.