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

Add keywords with script - XMP

Contributor ,
Oct 16, 2015 Oct 16, 2015

Copy link to clipboard

Copied

Hello everyone!

I need a script to add words in my keywords. It's possible?

I'm trying this:

activeDocument.XMPString ("ok Script");

ActiveDocument.Save (); // dont work

Thank cooperation!

TOPICS
Scripting

Views

1.7K

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

correct answers 1 Correct answer

Participant , Oct 19, 2015 Oct 19, 2015

As an option:

function save(doc, path, name){

    try{

        doc.save();

    }catch(e){

        doc.saveAs( File(path + '/' + name) );

    }

}

function setKeywords(keywords){

    var xmp = activeDocument.XMPString.toString(),

        startSubject = '<dc:subject><rdf:Bag>',

        endSubject = '</rdf:Bag></dc:subject>',

        words = keywords.split('\n');

        keywords = '';

    for(var i = 0; i < words.length; i++){

        keywords += '<rdf:li>' + words + '</rdf:li>';

    }

    if( xmp.indexOf(startSubj

...

Votes

Translate

Translate
Adobe
Participant ,
Oct 16, 2015 Oct 16, 2015

Copy link to clipboard

Copied

function save(doc, path){

    try{

        doc.save();

    }catch(e){

        doc.saveAs( Folder(path) );

    }

}

save( app.activeDocument, '~/Desktop' );

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
Community Expert ,
Oct 16, 2015 Oct 16, 2015

Copy link to clipboard

Copied

Try it:

var key = prompt("Input keyword","");

if (key!=null) {

  var st = app.activeDocument.XMPString;

  var str = "";

  if (st.match(/dc:subject/)==null) {

     str = "<dc:subject><rdf:bag><rdf:li>"

        + key + "</rdf:li></rdf:bag></dc:subject></dc:title>";

     st.replace("</dc:title>",str);

     app.activeDocument.XMPString = st;

  }

  else {

     str = "<rdf:li>" + key + "</rdf:li></rdf:Bag>";

     st = st.replace("</rdf:Bag>",str);

     app.activeDocument.XMPString = st;

  }

  app.activeDocument.save();

}

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
Contributor ,
Oct 19, 2015 Oct 19, 2015

Copy link to clipboard

Copied

Hello my friends,

I ran the scripts but my Keywords still empty.

Am I doing something wrong?

Screen Shot 2015-10-19 at 9.29.20 AM.png

Thanks for the collaboration..

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
Participant ,
Oct 19, 2015 Oct 19, 2015

Copy link to clipboard

Copied

LATEST

As an option:

function save(doc, path, name){

    try{

        doc.save();

    }catch(e){

        doc.saveAs( File(path + '/' + name) );

    }

}

function setKeywords(keywords){

    var xmp = activeDocument.XMPString.toString(),

        startSubject = '<dc:subject><rdf:Bag>',

        endSubject = '</rdf:Bag></dc:subject>',

        words = keywords.split('\n');

        keywords = '';

    for(var i = 0; i < words.length; i++){

        keywords += '<rdf:li>' + words + '</rdf:li>';

    }

    if( xmp.indexOf(startSubject) > 0 ){

        activeDocument.XMPString = xmp.replace( xmp.slice(xmp.indexOf(startSubject) + startSubject.length, xmp.indexOf(endSubject)), keywords );

    }

        else{

            activeDocument.XMPString = xmp.replace('</dc:title>', '</dc:title>' + startSubject + keywords + endSubject);

        }

    save( app.activeDocument, '~/Desktop', 'Add keywords from script' );

}

setKeywords('One\nTwo\nThree\nFour\nFive');

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