7 Replies Latest reply on Mar 18, 2013 7:20 AM by Cooroo

    AppleScript to check all pages within one Indesign (CS6) document have same size.

    hasi8

      I have bunch of InDesign (CS6) documents containing different page sizes (some are designed for a particular device and some are designed for multiple devices using alternate layouts). I need to assure all page sizes are same before I run a particular script.

       

       

      So I need a Applescript which can request a folder location of closed files and then open and run through the InDesigns in that folder (ignoring any other files) and then open a text file report saying all page sizes are same or not. (Sorry! for my English)

       

      Any help is much appreciated!

        • 1. Re: AppleScript to check all pages within one Indesign (CS6) document have same size.
          -hans- Level 4

          Hi,

          var selFolder = Folder.selectDialog();
          var inddFiles = selFolder.getFiles('*.indd');
          
          l = inddFiles.length;
          app.scriptPreferences.userInteractionLevel = UserInteractionLevels.NEVER_INTERACT;
          while(l--)
          {
          currDoc = app.open(inddFiles[l], false);
          
          allPagesBounds = currDoc.pages.everyItem().bounds;
          currDocPagesWidthHeight = new Array();
          for(var b = 0; b < allPagesBounds.length; b++)
          {
              h = allPagesBounds[b][2];
              w = allPagesBounds[b][3] - allPagesBounds[b][1];
              resString = '' + currDoc.pages[b].name + ': ' + w + ' x ' + h + '\n';
              currDocPagesWidthHeight.push(resString)
                  }
          toFile(currDoc.name.replace(/indd/,''), currDocPagesWidthHeight.join(''));
          currDoc.close(SaveOptions.NO);
              }
          app.scriptPreferences.userInteractionLevel = UserInteractionLevels.INTERACT_WITH_ALL;
          
          function toFile(targetName, pwh)
          {
              targetFile = File(selFolder + '/' + targetName + 'txt')
              targetFile.open('w');
              targetFile.write(pwh);
              targetFile.close()
                  }
          

           

          quick'n dirty this should list all pagesizes of indd-docs of a chosen folder in the chosen folder with matching inddDocName.

          Docs will open faceless ... Javascript.

           

          Hope it'll be of some help

           

          Hans-Gerd Claßen

          • 2. Re: AppleScript to check all pages within one Indesign (CS6) document have same size.
            -hans- Level 4

            good morning,

             

            changed it a bit. this'll only write a reportfile if there are pages with different pagesizes.

             

             

            #target Indesign
            
            var selFolder = Folder.selectDialog();
            var inddFiles = selFolder.getFiles('*.indd');
            
            l = inddFiles.length;
            app.scriptPreferences.userInteractionLevel = UserInteractionLevels.NEVER_INTERACT;
            while(l--)
            {
            currDoc = app.open(inddFiles[l], false);
            
            allPagesBounds = currDoc.pages.everyItem().bounds;
            currDocPagesWidthHeight = new Array();
            for(var b = 0; b < allPagesBounds.length; b++)
            {
                h = allPagesBounds[b][2];
                w = allPagesBounds[b][3] - allPagesBounds[b][1];
                resString = '' + currDoc.pages[b].name + ': ' + w + ' x ' + h + '\n';
                currDocPagesWidthHeight.push(resString)
                    }
                
                var samePageSizesOrNot = checkUnique(currDocPagesWidthHeight);
                switch(samePageSizesOrNot)
                {
                    case false : 
            toFile(currDoc.name.replace(/indd/,''), currDocPagesWidthHeight.join(''));
            currDoc.close(SaveOptions.NO);
            break;
            default : currDoc.close(SaveOptions.NO);
            break;
            }
            
                }
            app.scriptPreferences.userInteractionLevel = UserInteractionLevels.INTERACT_WITH_ALL;
            
            function toFile(targetName, pwh)
            {
                targetFile = File(selFolder + '/' + targetName + 'txt')
                targetFile.open('w');
                targetFile.write(pwh);
                targetFile.close()
                    }
            
            function checkUnique(someArray) { 
                     var obj = {}  ;  
                var tmpArray = []  ;  
                     for (var i = 0; i < someArray.length; i++) { 
                             var currItem = someArray[i];  
                    if (! obj[currItem]) {        
                        obj[currItem] = true ;  
                                                 tmpArray.push(currItem);  
                        } ;
                             }; 
                if (tmpArray.length === 1)
                {
                    return true;
                    }else{
                        return false;}
                        };
            

            res.png

            • 3. Re: AppleScript to check all pages within one Indesign (CS6) document have same size.
              hasi8 Level 1

              Thank you soooo much Hans!

               

              This is really great! Could it be possible to run on a bunch of folders and subfolders and in the end create a single txt file report?

               

              Screen Shot 2013-03-11 at 4.57.57 PM.png

               

              Thanks,

              Hasi

              • 4. Re: AppleScript to check all pages within one Indesign (CS6) document have same size.
                -hans- Level 4

                sure,

                 

                still no error-handling included, so use on own risk ;-) ...

                 

                #target Indesign
                var selFolder = Folder.selectDialog();
                if(!selFolder) {exit();};
                var allFiles = selFolder.getFiles('*.*');
                
                var currDate = getDate();
                 var currLogFile = File(selFolder.toString() + '/' + currDate + 'pagesSizeLogFile.txt');
                
                 doStuff(allFiles);
                
                 currLogFile.execute();
                
                 function doStuff(filesFoldersArray){
                var l = filesFoldersArray.length;
                app.scriptPreferences.userInteractionLevel = UserInteractionLevels.NEVER_INTERACT;
                while(l--)
                {
                  var   currItem = filesFoldersArray[l];
                if(currItem instanceof(Folder)){
                    nextItems = currItem.getFiles('*.*');
                    doStuff(nextItems);
                    }
                    else if (    currItem.displayName.indexOf('indd') != -1){
                    
                    currDoc = app.open(currItem, false);
                
                allPagesBounds = currDoc.pages.everyItem().bounds; 
                currDocPagesWidthHeight = [currDoc.fullName.toString() + ':\n']; 
                for(var b = 0; b < allPagesBounds.length; b++) {
                    h = allPagesBounds[b][2];
                    w = allPagesBounds[b][3] - allPagesBounds[b][1];
                    resString = '' + currDoc.pages[b].name + ': ' + w + ' x ' + h + '\n';
                    currDocPagesWidthHeight.push(resString)
                        }
                    
                    var samePageSizesOrNot = checkUnique(currDocPagesWidthHeight);
                    switch(samePageSizesOrNot)
                    {
                        case false : 
                toFile(currDocPagesWidthHeight.join(''));
                currDoc.close(SaveOptions.NO);
                break;
                default : currDoc.close(SaveOptions.NO); break; }
                
                    }
                }
                app.scriptPreferences.userInteractionLevel = UserInteractionLevels.INTERACT_WITH_ALL;
                }
                
                function toFile(pwh)
                {
                        currLogFile.open('a');
                    currLogFile.write(pwh);
                    currLogFile.close()
                        }
                
                function checkUnique(someArray) { 
                           var tmpArray = []  ;  
                    var tmpString = '';
                         for (var i = 1; i < someArray.length; i++) { 
                             currItem = someArray[i];
                             if (tmpString.indexOf(currItem.slice(2,-1)) === -1){
                                tmpString = tmpString + ' ' + currItem;
                                                     tmpArray.push(currItem);  
                            } ;
                                 }; 
                    if (tmpArray.length === 1)
                    {
                        return true;
                        }else{
                            return false;}
                            };
                        
                        function getDate(){
                    var d = new Date();
                var day = d.getDate();
                if(day < 10){day = '0' + day;};
                var month = d.getMonth() +1;
                if(month < 10){month = '0' + month;};
                var year = '' + d.getFullYear();
                var hours = d.getHours();
                var minutes = d.getMinutes();
                var seconds = d.getSeconds();
                 var dateString = month + day  + year.substring(2) + '_'  + hours + minutes + seconds + '_';
                 return dateString;
                 }
                
                
                • 5. Re: AppleScript to check all pages within one Indesign (CS6) document have same size.
                  Cooroo Level 1

                  Puzzled - surely this is Java not Applescript as requested??

                  • 6. Re: AppleScript to check all pages within one Indesign (CS6) document have same size.
                    -hans- Level 4

                    It's a javascript (Extendscript) and will run on both mac and pc

                    • 7. Re: AppleScript to check all pages within one Indesign (CS6) document have same size.
                      Cooroo Level 1

                      Thought so. Just OP asked for AS and seemed happy with JS! I think I need to learn JS... I am too stuck in my ways!