3 Replies Latest reply on May 14, 2014 1:38 PM by pixxxel schubser

    File Name from Character through hard return. Almost there.

    cathykka

      Hi all! I have a script that is naming my files by the characters in two text frames.

      It works... to a point.

      For some reason it is duplicating the name.

      This is the final result. > test-2-wealth-file-stuff,2-wealth-file-+-stuff.jpg

      when it should be this. > test-2-wealth-file-stuff.jpg

      for some reason it is adding > ,2-wealth-file-+-stuff

       

      any idea why? Thanks in advance.

       

      main ();
      
      function main() {
      
      var curDoc = app.activeDocument;
      
      
      // loop through all pages
      for ( var i = 0; i < curDoc.pages.length; i++ ) {
          // the current page
          var curPage = curDoc.pages[i];
          var pName = curPage.name;
      
      
          // controls the loop
          var controller = true;
          // all paragraphs on the current page
      
      
      
        var allPages = (curPage.textFrames.everyItem().paragraphs[0]); {
      pageName=allPages.characters.itemByRange(0,allPages.contents.toString().indexOf("^p") -1);
      
      
        var paraName = "" + pageName.contents;
      var paraString = "-" + paraName.replace( /\s+$/ , "" ).replace( /\s+/g , "-" ).toLowerCase().replace('+', '');
      
      
      }
      
      
      
      var folderPath = "~/-client/" ;
         {
              var appendix = paraString;
          }
         
          var filePath = folderPath + "/" + curDoc.name.replace(/\.indd$/,"") + appendix + ".jpg";
          var myFile = File( filePath );
      
          with ( app.jpegExportPreferences) {
              jpegQuality = JPEGOptionsQuality.MAXIMUM; // low medium high maximum
              exportResolution = 72;
              jpegExportRange = ExportRangeOrAllPages.exportRange;
              pageString = pName;
          }
          curDoc.exportFile( ExportFormat.jpg, myFile, false );
        } // end for > pages
      
      
      } // end for > main