• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Copy keywords into title field, keep in keywords field

Explorer ,
May 31, 2013 May 31, 2013

Copy link to clipboard

Copied

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();

        }

    }

}

TOPICS
Scripting

Views

1.1K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Jun 01, 2013 Jun 01, 2013

Copy link to clipboard

Copied

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;

    }

};


Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 01, 2013 Jun 01, 2013

Copy link to clipboard

Copied

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Jun 01, 2013 Jun 01, 2013

Copy link to clipboard

Copied

No, they are just the Schema's namespace.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 03, 2013 Jun 03, 2013

Copy link to clipboard

Copied

Awesome- that works great! How do I add a space between them? Also, I am not seeing where it changes the ";" to a "," but, it is doing it- which is perfect. How is it doing it? Where is it receiving that command?

I have tried going in and making a couple of changes, but none of them do anything.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Jun 03, 2013 Jun 03, 2013

Copy link to clipboard

Copied

LATEST

There was no need to make a change as it extracts an array and this is converted to a string so that puts the commas inbetween.

A simple replace can add a space ....

#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().replace(/,/g,', ');// Replace a comma with comma space

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

md.title ='';

md.title = Keys;

    }

};

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines