1 Reply Latest reply on Jul 30, 2009 1:10 PM by Dave Saunders

    CS3 to CS4 Metadata population script incompatibility?

    VictorCormier

      Hello Ladies and Gentlemen,

       

      I was looking to probe your collective expertise on a question I have run across.  I have been notified of a, theoretically, wonderful script that promises to populate the title/description/keywords metadata info of a document with text from said document (based on paragraph styles applied to the text).  For reasons beyond my humble grasp this script seems to no longer function properly in CS4.  Perhaps a specific call's wording has changed between versions, or perhaps the entire syntax of the script no longer applies. 

      //Set to 4.0/CS2 scripting object model
      app.scriptPreferences.version = 4.0;
      
      myDocument = app.activeDocument; //work on active document
      
      //===== Remove/Replace certain characters such as paragraph markers =====\\
              function replaceByCode(myMetaIn, myTotalCharacters)
              {
                 myCharCodeList = new Array(
                      "13", // Paragraph Marker
                      "10", // Soft Return 
                          );
                    
                  myCharReplacementList = new Array(
                     "", // Remove paragraph markers
                     "", // Remove soft returns 
                          );
                      
                    var myTotalSpecialCharacters = myCharCodeList.length;
                    var myMetaOut = myMetaIn;
      
                    for (z = myTotalSpecialCharacters; z >= 0; z--)
                          {
                          for (y = myTotalCharacters; y >= 0; y--)
                            {
                               myCharacterCode = myMetaIn.charCodeAt(y) + "";
                                if (myCharacterCode == myCharCodeList[z])
                                   {
                                      myCharacter = myMetaIn.charAt(y);
                                       myMetaOut = myMetaOut.replace(myCharacter, myCharReplacementList[z]);
                                       }
                                   }
                              }
      
                              return (myMetaOut)
                      }                 
                      
      //===== Search for text with the paragraph style "title" =====\\
      
      var myTitle = " ";
      try{
          app.findPreferences = null;
          app.changePreferences = null;
          var titleSearch = myDocument.search(undefined,false,false,undefined, {appliedParagraphStyle:'title'});
      
          for (i = 0; i < titleSearch.length; i++)
              {
                  myTitleParagraph = titleSearch[i];
              }
      
          myTitle = myTitleParagraph.contents; 
          myTitleTotalCharacters = myTitle.length;
          myTitle = replaceByCode(myTitle, myTitleTotalCharacters); 
          }
          catch(e){}
          
      //===== Search for text with the paragraph style "description" =====\\    
      
      var myDescription = " ";
      try{
          app.findPreferences = null;
          app.changePreferences = null;
          var descriptionSearch = myDocument.search(undefined,false,false,undefined, {appliedParagraphStyle:'description'});
      
          for (i = 0; i < descriptionSearch.length; i++)
              {
                  myDescriptionParagraph = descriptionSearch[i];
              }
      
          myDescription = myDescriptionParagraph.contents;
          }
          catch(e){}
          
      //===== Search for text with the paragraph style "keywords" =====\\        
      
      var myKeywords = " ";
      try{
          app.findPreferences = null;
          app.changePreferences = null;
          var keywordsSearch = myDocument.search(undefined,false,false,undefined, {appliedParagraphStyle:'keywords'});
      
          for (i = 0; i < keywordsSearch.length; i++)
              {
                  myKeywordsParagraph = keywordsSearch[i];
              }
      
          myKeywords = myKeywordsParagraph.contents;
          myKeywords = myKeywords.split(","); // Create an array from the string. Keywords should be seperated by a comma.
          }
          catch(e){}
      
      //===== Assign the text found from searching to XMP fields =====\\    
      myDocument.metadataPreferences.documentTitle = myTitle;
      myDocument.metadataPreferences.description = myDescription;
      myDocument.metadataPreferences.keywords = myKeywords; 
      
      

       

      Picture 1.png

       

      This error is returned when the script is run verbatim, but that seems to be solely because it thinks the "keywords" paragraph style is applied to no text.  Removing the keyword sections of the script causes it to run without error, but writes no data to the XMP fields.

       

      Any information you have or enlightenment you may provide would be helpful and appreciated.