Skip to main content
Known Participant
May 31, 2013 5:30 PM UTC
Question

Copy keywords into title field, keep in keywords field

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 is closed to new replies. Start a new post to keep the conversation going.

5 replies

Paul Riggott
Inspiring
Jun 1, 2013 8:44 AM UTC

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;

    }

};


Translate
pwfasprodAuthor
Known Participant
Jun 1, 2013 1:12 PM UTC

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?

Translate
Paul Riggott
Inspiring
Jun 1, 2013 4:36 PM UTC

No, they are just the Schema's namespace.

Translate