5 Replies Latest reply on Sep 19, 2014 2:50 PM by rudytj

    non-scripter attempting a metatagging script

    rudytj

      my script is doing everything i want except it is converting all spaces and periods to semicolons in the final metatag and i cannot figure out why.

       

      It will be VERY obvious that the attached script is nothing but a bunch of snippets clipped together to perform most of what i want...

       

      I want to run this script at the end as i am completing a project to insert the needed metatags.

       

      i want the project name

      i want the copyright info

      i want keywords to include all images used in the document

      i want to be able to add keywords.

       

       

      to run this script you will need a character style called    KeywordsCStyle

       

       

       

      //-----document title and copyright---------

      var myDocument = app.activeDocument;

      with (myDocument.metadataPreferences){ 

          //author = "Adobe"; 

          copyrightInfoURL = "UPMC.com" 

          copyrightNotice = "© 2014 UPMC"; 

          copyrightStatus = CopyrightStatus.yes; 

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

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

          //jobName = "XMP_Example_2003"; 

          //var myNewContainer = createContainerItem("http://ns.adobe.com/xap/1.0/", "email"); 

          //setProperty("http://ns.adobe.com/xap/1.0/", "email/*[1]", "someone@adobe.com"); 

          }

      //----------------------------------------------------

      with (myDocument.metadataPreferences){

              //author = "scott rudy";

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

              }

      //-------------------------------------------------//

      //var curDocTitle = app.activeDocument.metadataPreferences.documentTitle;

      //var curAuthor = app.activeDocument.metadataPreferences.author;

      var curKeywords = app.activeDocument.metadataPreferences.keywords;

      Array.prototype.unique = function (){

          var r = new Array();

          o:for(var i = 0, n = this.length; i < n; i++){

              for(var x = 0, y = r.length; x < y; x++){

                  if(r[x]==this[i]) continue o;}

              r[r.length] = this[i];}

          return r;

      }

      function addXMP(/*find GREP*/findString, /*para style*/paraStyle, /*chr style*/chrStyle, /*insert to*/XMPdest){

        // reset search fields

        app.findGrepPreferences = NothingEnum.nothing;

        app.changeGrepPreferences = NothingEnum.nothing;

        // setting search parameters

        if(findString)app.findGrepPreferences.findWhat = findString;

        if(paraStyle)app.findGrepPreferences.appliedParagraphStyle = paraStyle;

        if(chrStyle)app.findGrepPreferences.appliedCharacterStyle = chrStyle;

       

        switch (XMPdest){

          // insert keywords

          case "Keywords":

            var myKeywords = app.activeDocument.findGrep();

            var myKeys = Array();

            // loop through keywords and get contents

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

              myKeys.push(myKeywords[i].contents);

            //myKeys.sort();

            // delete duplicates

            //myKeys = myKeys.unique();

            // insert Keywords to document XMP

            app.activeDocument.metadataPreferences.keywords = myKeys;

            break;

          // Heading search/insert

          case "Heading":

            var myHeading = app.activeDocument.findGrep();

            app.activeDocument.metadataPreferences.documentTitle = myHeading[0].contents;

            break;

          // Author search/insert

         // case "Author":

          //  var myAuthor = app.activeDocument.findGrep();

          //  app.activeDocument.metadataPreferences.author = myAuthor[0].contents;

         //   break;

        }

      }

      // copy all image names //----------------------------------------------//

      f = app.activeDocument.textFrames.add({geometricBounds:[0,0,"20mm","20mm"]}); 

      f.contents = app.activeDocument.links.everyItem().name.join("\r"); 

      f.parentStory.texts[0].select(); 

      //-----------change character style-------------------//

      var cName = "KeywordsCStyle"; 

        var mCstyle = app.activeDocument.characterStyles.item(cName); 

        if (mCstyle.isValid) 

             app.selection[0].applyCharacterStyle(mCstyle);

      //---------------------------------------//

      app.copy(); 

       

       

       

       

      //-----------------------------------------------------------------------//

       

       

      // add Keywords

      addXMP("\\w{1,}","","KeywordsCStyle","Keywords");

       

      // add Heading

      //addXMP("","HeadingPStyle","","Heading");

       

      //add Author

      addXMP("","AuthorPStyle","","Author");

      //

      //----delete image names textbox--------

      f.remove();

        • 1. Re: non-scripter attempting a metatagging script
          Jump_Over Level 5

          rudytj wrote:

           

          ...my script is doing everything i want except it is converting all spaces and periods to semicolons in the final metatag and i cannot figure out why...

          ...

          app.activeDocument.metadataPreferences.keywords = myKeys;

          ...

          addXMP("\\w{1,}","","KeywordsCStyle","Keywords");

          ...

           

          myKeys is an array of words.

          Each doc link is divided to words (even 1-letter long) since app.findGrepPreferences.findWhat property is set to "\\w{1,}"

               ==> means find Any Word Character (1+long)

           

          spaces and periods (and any "no-word" characters) are ommited.

           

          The question is how your keyword (created from a link name) supposes to look like?

           

          Jarek

          • 2. Re: non-scripter attempting a metatagging script
            rudytj Level 1

            i would like it to be the complete link name including the file extension and if i tag a phrase with the  character style "KeywordsCStyle"  i would like it to appear together as well. so i need the results to include the . before the file extension and any spaces between words.

             

            i will look into your lead and if you could continue to try to help me it would be most appreciated

             

             

            thank you in advance

             

            scott

            • 3. Re: Re: non-scripter attempting a metatagging script
              Jump_Over Level 5

              Hi,

               

              If your goal is to set an entire link name as a particular keyword ==> whole part with creating temporary textFrame, applying charStyle and findGrep() looks like unnecessary...

               

              the line:

              app.activeDocument.metadataPreferences.keywords = app.activeDocument.links.everyItem().name;
              

               

              should do a job

               

              Jarek

              • 4. Re: non-scripter attempting a metatagging script
                rudytj Level 1

                but that will eliminate my ability to tag words in the document with the character style "KeywordsCStyle" and have those words also appear in the metatag along with to the links.

                 

                 

                thank you for all your assistance in this task!!!

                 

                scott

                • 5. Re: non-scripter attempting a metatagging script
                  rudytj Level 1

                  I decided to give up on the character style to add keywords so i have to thank JUmp_over for all the help with my complete script...

                   

                  here it is after i cleaned it up if anybody else has a need to add keywords to their indesign file (and ultimately to the resulting PDFs

                   

                   

                   

                  //-----document title and copyright---------

                  var myDocument = app.activeDocument;

                  with (myDocument.metadataPreferences){ 

                      copyrightInfoURL = "UPMC.com" 

                      copyrightNotice = "© 2014 UPMC"; 

                      copyrightStatus = CopyrightStatus.yes; 

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

                      }

                  //---------------------add document name-------------------------------

                  with (myDocument.metadataPreferences){

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

                          }

                  //-----------------------images to keywords--------------------------//

                  app.activeDocument.metadataPreferences.keywords = app.activeDocument.links.everyItem().name;

                  //-------------open file info dialog box---------------------

                  app.menuActions.itemByID(89092).invoke()