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

Scripts to insert metadata automatically to document with paragraph style

Community Beginner ,
Oct 27, 2013 Oct 27, 2013

Copy link to clipboard

Copied

Hello,

I am trying to find a way to automatically insert  metadata into my document through paragraph style in indesign cs5.5.

This will be myDocument title, the Author name and myDocument description.

Is there anyone who can help me with this project?

Thanks.

TOPICS
Scripting

Views

3.6K

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

Enthusiast , Oct 28, 2013 Oct 28, 2013

Place the script in the following location: C:\Program Files\Adobe\Adobe InDesign CS6\Scripts\startup scripts

If you close the document the script will automatically put the metadata in your indesign file (use ctrl+w or menu -> file -> close option to close the file)

Code:

#targetengine session

//if you want to test the script for your active document, comment the below line else copy the script in your startup folder

app.menuActions.itemByName("Close").eventListeners.add("beforeInvoke", function()

{

v

...

Votes

Translate

Translate
Advocate ,
Oct 27, 2013 Oct 27, 2013

Copy link to clipboard

Copied

Hi abmiss1,

I have a doubt with your above request, what i understood!

If the the paragraph style is "myDocument title" means the contents insert to : XMP Document title.

If the the paragraph style is "Author Name" means the contents insert to : XMP Author name.

If the the paragraph style is "myDocument description" means the contents insert to : XMP Description.

Please find the below JS cod its simply created the XMP meta information.

var myDocument = app.activeDocument;

with (myDocument.metadataPreferences){

    author = "Adobe";

    copyrightInfoURL = "http://www.adobe.com";

    copyrightNotice = "This document is copyrighted.";

    copyrightStatus = CopyrightStatus.yes;

    description = "Example of xmp metadata scripting in InDesign CS";

    documentTitle = "XMP Example";

    jobName = "XMP_Example_2003";

    keywords = ["animal", "mineral", "vegetable"];

    }

Otherwise please clearly expalin what is your requirement.

thx,

csm_phil

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
Enthusiast ,
Oct 27, 2013 Oct 27, 2013

Copy link to clipboard

Copied

Try this,

var myDoc = app.activeDocument;

var authorText, docDescripText;

app.findGrepPreferences = app.changeGrepPreferences = null;

app.findGrepPreferences.findWhat = '.+';

found = app.activeDocument.findGrep (true);

for (j = 0; j < found.length; j++){

     var foundText = found.contents;

     if(found.texts[0].appliedParagraphStyle.name=="authorName")//author paragraph style

     {

         authorText=found.contents;

     }

     else if(found.texts[0].appliedParagraphStyle.name=="docDescription")//description paragraph style

     {

         docDescripText=found.contents;

     }

}

with (myDoc.metadataPreferences){

    author = authorText;

    documentTitle = myDoc.name.split(".indd")[0];

    description = docDescripText;

    }

Vandy

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 Beginner ,
Oct 28, 2013 Oct 28, 2013

Copy link to clipboard

Copied

Thank you very much Vandy. The script work good. The only thing I want to ask you again is ( maybe I wasn't explicit on my original post 😞 The author name will always be the same but the Document Title and the Document Description will varry, this is why I wanted to do it with paragraph style. Also I was wondering if I can apply like 2 or 3 styles to the Document descrition at the same time. So in summary (author name="My Name", Document Title = "Par Style1" "Par Style2"  And my Document Description will be also define with multiple paragraph styles.

I also need help to make the srypt run automatically as I open any document or close it.

Thank so much for your help.

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 Beginner ,
Oct 28, 2013 Oct 28, 2013

Copy link to clipboard

Copied

Thank you Phil. Sorry for the confusion in my original post, I try to explain little bit my need in my answer to Vandy.

Please refer to it if you can help. Again thank you for your help.

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
Enthusiast ,
Oct 28, 2013 Oct 28, 2013

Copy link to clipboard

Copied

Place the script in the following location: C:\Program Files\Adobe\Adobe InDesign CS6\Scripts\startup scripts

If you close the document the script will automatically put the metadata in your indesign file (use ctrl+w or menu -> file -> close option to close the file)

Code:

#targetengine session

//if you want to test the script for your active document, comment the below line else copy the script in your startup folder

app.menuActions.itemByName("Close").eventListeners.add("beforeInvoke", function()

{

var myDoc = app.activeDocument;

var docTitleText="";

var docDescripText="";

app.findGrepPreferences = app.changeGrepPreferences = null;

app.findGrepPreferences.findWhat = '.+';

found = app.activeDocument.findGrep (true);

for (j = found.length-1; j >=0 ; j--)

{

    var foundText = found.contents;

   

    //You can define multiple Paragraph style for Document Title

   

    if(found.texts[0].appliedParagraphStyle.name=="docTitle1")

    {

        docTitleText=found.contents;

    }

    else if(found.texts[0].appliedParagraphStyle.name=="docTitle2")

    {

        docTitleText=docTitleText + " " + found.contents;

    }

    else if(found.texts[0].appliedParagraphStyle.name=="docTitle3")

    {

        docTitleText=docTitleText + " " + found.contents;

    }

    //You can define multiple Paragraph style for Document Description

    else if(found.texts[0].appliedParagraphStyle.name=="docDescription1")

    {

        docDescripText=found.contents;

    }

    else if(found.texts[0].appliedParagraphStyle.name=="docDescription2")

    {

        docDescripText=docDescripText + " " + found.contents;

    }

    else if(found.texts[0].appliedParagraphStyle.name=="docDescription3")

    {

        docDescripText=docDescripText + " " + found.contents;

    }

}

with (myDoc.metadataPreferences){

    author = "My Name";

    documentTitle = docTitleText;

    description = docDescripText;

    }

});

Vandy

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 Beginner ,
Oct 29, 2013 Oct 29, 2013

Copy link to clipboard

Copied

LATEST

Thank you Vandy, this script work like a charm.

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