6 Replies Latest reply on Oct 29, 2013 8:19 AM by abmiss1

    Scripts to insert metadata automatically to document with paragraph style

    abmiss1

      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.

        • 1. Re: Scripts to insert metadata automatically to document with paragraph style
          csm_phil Level 4

          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

          • 2. Re: Scripts to insert metadata automatically to document with paragraph style
            Sajeev Sridharan Level 4

            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[j].contents;

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

                 {

                     authorText=found[j].contents;

                 }

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

                 {

                     docDescripText=found[j].contents;

                 }

            }

             

            with (myDoc.metadataPreferences){

                author = authorText;

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

                description = docDescripText;

                }

             

             

            Vandy

            • 3. Re: Scripts to insert metadata automatically to document with paragraph style
              abmiss1 Level 1

              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.

              • 4. Re: Scripts to insert metadata automatically to document with paragraph style
                abmiss1 Level 1

                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.

                • 5. Re: Scripts to insert metadata automatically to document with paragraph style
                  Sajeev Sridharan Level 4

                  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[j].contents;

                     

                      //You can define multiple Paragraph style for Document Title

                     

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

                      {

                          docTitleText=found[j].contents;

                      }

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

                      {

                          docTitleText=docTitleText + " " + found[j].contents;

                      }

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

                      {

                          docTitleText=docTitleText + " " + found[j].contents;

                      }

                   

                   

                      //You can define multiple Paragraph style for Document Description

                   

                   

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

                      {

                          docDescripText=found[j].contents;

                      }

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

                      {

                          docDescripText=docDescripText + " " + found[j].contents;

                      }

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

                      {

                          docDescripText=docDescripText + " " + found[j].contents;

                      }

                  }

                   

                   

                  with (myDoc.metadataPreferences){

                      author = "My Name";

                      documentTitle = docTitleText;

                      description = docDescripText;

                      }

                  });

                   

                   

                  Vandy

                  • 6. Re: Scripts to insert metadata automatically to document with paragraph style
                    abmiss1 Level 1

                    Thank you Vandy, this script work like a charm.