4 Replies Latest reply on Nov 13, 2009 2:46 PM by MikeBrog

    InDesign Profanity check

    MikeBrog Level 1

      We recently printed a publication that contained a typo.  The typo appeared to be a profanity.  I planned on scripting Word to check for profanities, but it makes more sense to check the InDesign file as it will contain the final version of the text and can be done once instead of once for each separate article.

       

      I have a list of profanities that I can check for. Could anyone point me in the direction of how to script a search window that will allow the user to check the document for all profanities and then allow the user to click a "Next" button to move from once occurrence to the next so that they can accept the occurance or edit it?

       

      Thank you.

        • 1. Re: InDesign Profanity check
          Thomas B. Nielsen Level 3

          Hi Mike,

           

          Here is something that might get you, or someone else started.

           

          It's not _the_ solution, it has flaws but should get you started.

          You could consider having the script add an xml tag to each found profanity, and then after the script is run, go through all the xml tags manually.

           

          But hey, have a go and see what you can make of it.

           

          This script requires you to have a list of all the profanities in a text file, one profanity on each line.

           

          Hope it's helpfull in some way.

           

          #targetengine "session"
          
          // This script has one major flaw - you can not zoom or center the screen on the selection ...
          var curItem = 0;
          var myFoundItems = new Array ();
          
          if (app.documents.length > 0) { 
               var myDocument = app.activeDocument;
               main();
          } else {
               alert("Please open a document");
               exit();
          }
          
          
          var win = new Window( "window", "Browse items" );
          win.myPanel = win.add("panel");
          win.myPanel.myGroup = win.myPanel.add('group');
          win.myPanel.myGroup.leftButton = win.myPanel.myGroup.add("button", undefined, "<-");
          win.myPanel.myGroup.rightButton = win.myPanel.myGroup.add("button", undefined, "->");
          
          win.myPanel.mySecGroup = win.myPanel.add('group');
          win.myPanel.mySecGroup.doneButton = win.myPanel.mySecGroup.add("button", undefined, "Done");
          
          myDocument.select(myFoundItems[0]);
          
          win.myPanel.myGroup.rightButton.onClick = function() {
               if (curItem == myFoundItems.length-1) {
                    curItem = 0;
                    myDocument.select(myFoundItems[curItem]);
                    // implement zoom
               } else {
                    curItem = curItem+1;
                    myDocument.select(myFoundItems[curItem]);
                    // implement zoom
               }
          }
          
          win.myPanel.myGroup.leftButton.onClick = function() {
               if (curItem == 0) {
                    curItem = myFoundItems.length-1;
                    myDocument.select(myFoundItems[curItem]);
                    // implement zoom
               } else {
                    curItem = curItem-1;
                    myDocument.select(myFoundItems[curItem]);
                    // implement zoom
               }
          }
          
          win.myPanel.mySecGroup.doneButton.onClick = function() {
               this.window.hide();
          }
          win.center();
          win.show();
          
          function main() {
               try {
                    var script = app.activeScript;
               } catch(err) {
                    var script = File(err.fileName);
               }
          
               var myScriptFolderPath = script.path;
               var myFindChangeFile = File.openDialog("Choose the file containing the profanities (one word each line"); //new File(myScriptFolderPath + "/profanities.txt"); 
               //alert(myFindChangeFile)
               myFindChangeFile = File(myFindChangeFile);
               var myResult = myFindChangeFile.open("r", undefined, undefined);
               if(myResult == true){
                    app.findTextPreferences = NothingEnum.nothing;
                    app.changeTextPreferences = NothingEnum.nothing;
                    //Loop through the find/change operations.
                    do {
                         //read 1 line into myLine
                         myLine = myFindChangeFile.readln();
                         //alert(myLine);
                         doSearchAndReplace(myLine, app.activeDocument);
                              
                    } while(myFindChangeFile.eof == false);
                         myFindChangeFile.close();
                         // reset search
                         app.findTextPreferences = NothingEnum.nothing;
                         app.changeTextPreferences = NothingEnum.nothing;
               }
               //alert(myFoundItems.length);
               if (myFoundItems.length < 1) {
                    alert("No matches found!");
                    exit();
               }
          }
          
          function doSearchAndReplace(stringfind, searchin) {
               app.findTextPreferences.findWhat = stringfind;
               
               //Set the find options.
               app.findChangeTextOptions.caseSensitive = false;
               app.findChangeTextOptions.includeFootnotes = false;
               app.findChangeTextOptions.includeHiddenLayers = false;
               app.findChangeTextOptions.includeLockedLayersForFind = false;
               app.findChangeTextOptions.includeLockedStoriesForFind = false;
               app.findChangeTextOptions.includeMasterPages = false;
               app.findChangeTextOptions.wholeWord = true;
               
               myFoundItems = myFoundItems.concat(searchin.findText()); //.push(myNewFoundItems.slice(0, myFoundItems.length-1));
          }
          
          // Function By Dave Saunders - http://jsid.blogspot.com
          function zoomObject(theObj) {
           try {
            var objBounds = theObj.geometricBounds;
           } catch (e) {
            throw "Object doesn't have bounds."
           }
           var ObjHeight = objBounds[2] - objBounds[0];
           var ObjWidth = objBounds[3] - objBounds[1];
           var myWindow = app.activeWindow;
           var pageBounds = myWindow.activePage.bounds;
           var PgeHeight = pageBounds[2] - pageBounds[0];
           var PgeWidth = pageBounds[3] - pageBounds[1];
           var hRatio = PgeHeight/ObjHeight;
           var wRatio = PgeWidth/ObjWidth;
           var zoomRatio = Math.min(hRatio, wRatio);
           app.select(theObj); // to make active the page that holds theObj
           myWindow.zoom(ZoomOptions.fitPage);
           myWindow.zoomPercentage = myWindow.zoomPercentage * zoomRatio;
           exit() // Because there's no point in doing this if you don't exit to let the user see
          }
          

          --

          Thomas B. Nielsen

          http://www.lund-co.dk

          • 2. Re: InDesign Profanity check
            MikeBrog Level 1

            Thomas,

             

            Thanks for the more than generous start.  The only major issue I had with the code you supplied is that the pages would not change based on where a word was found.  It would never leave the page that I started on, but would highlight the word on a different page.

             

            I tried very hard to figure out how to go to different pages, but was unable to figure it out.  I ended up moving on from that to try and implement some sort of zoom code.  Once I added the zoom code, the script is now moving through the document as it should and the highlighted word is always brought into view regardless of where it is on the page.

             

            The code I added was a single line added at several places:

            app.activeWindow.zoomPercentage = 300

             

            I also replaced the file browse dialog in favor of a fixed path.

             

            Now I just need to figure out how to add a summary to the panel!

             

            Here is the code I have so far:

            #targetengine "session"
            // This script has one major flaw - you can not zoom or center the screen on the selection ...
            var curItem = 0;
            var myFoundItems = new Array ();
            if (app.documents.length > 0) {
                 var myDocument = app.activeDocument;
                 main();
            } else {
                 alert("Please open a document");
                 exit();
            }

            var win = new Window( "window", "Browse items" );
            win.myPanel = win.add("panel");
            win.myPanel.myGroup = win.myPanel.add('group');
            win.myPanel.myGroup.leftButton = win.myPanel.myGroup.add("button", undefined, "<-");
            win.myPanel.myGroup.rightButton = win.myPanel.myGroup.add("button", undefined, "->");
            win.myPanel.mySecGroup = win.myPanel.add('group');
            win.myPanel.mySecGroup.doneButton = win.myPanel.mySecGroup.add("button", undefined, "Done");

            myDocument.pages.lastItem();
                 
            myDocument.select(myFoundItems[0]);
            win.myPanel.myGroup.rightButton.onClick = function() {
                 if (curItem == myFoundItems.length-1) {
                      curItem = 0;
                      myDocument.select(myFoundItems[curItem]);
                myDocument.Page.id
                      // implement zoom
                      app.activeWindow.zoomPercentage = 300
                 } else {
                      curItem = curItem+1;
                      myDocument.select(myFoundItems[curItem]);
                      // implement zoom
                app.activeWindow.zoomPercentage = 300
                 }
            }
            win.myPanel.myGroup.leftButton.onClick = function() {
                 if (curItem == 0) {
                      curItem = myFoundItems.length-1;
                      myDocument.select(myFoundItems[curItem]);
                      // implement zoom
                app.activeWindow.zoomPercentage = 300
                 } else {
                      curItem = curItem-1;
                      myDocument.select(myFoundItems[curItem]);
                      // implement zoom
                app.activeWindow.zoomPercentage = 300
                 }
            }
            win.myPanel.mySecGroup.doneButton.onClick = function() {
                 this.window.hide();
            }
            win.center();
            win.show();
            app.activeWindow.zoomPercentage = 300
            function main() {
                 try {
                      var script = app.activeScript;
                 } catch(err) {
                      var script = File(err.fileName);
                 }
                 var myScriptFolderPath = script.path;
                 var myFindChangeFile = "C:\\Falcon\\profanity-list.txt"  //File.openDialog("Choose the file containing the profanities (one word each line");
                 //new File(myScriptFolderPath + "/profanities.txt");
                 //alert(myFindChangeFile)
                 myFindChangeFile = File(myFindChangeFile);
                 var myResult = myFindChangeFile.open("r", undefined, undefined);
                 if(myResult == true){
                      app.findTextPreferences = NothingEnum.nothing;
                      app.changeTextPreferences = NothingEnum.nothing;
                      //Loop through the find/change operations.
                      do {
                         //read 1 line into myLine
                         myLine = myFindChangeFile.readln();
                         //alert(myLine);
                         doSearchAndReplace(myLine, app.activeDocument);
                             
                      } while(myFindChangeFile.eof == false);
                         myFindChangeFile.close();
                         // reset search
                         app.findTextPreferences = NothingEnum.nothing;
                         app.changeTextPreferences = NothingEnum.nothing;
                 }
                 //alert(myFoundItems.length);
                 if (myFoundItems.length < 1) {
                      alert("No matches found!");
                      exit();
                 }
            }
            function doSearchAndReplace(stringfind, searchin) {
                 app.findTextPreferences.findWhat = stringfind;
                
                 //Set the find options.
                 app.findChangeTextOptions.caseSensitive = false;
                 app.findChangeTextOptions.includeFootnotes = false;
                 app.findChangeTextOptions.includeHiddenLayers = false;
                 app.findChangeTextOptions.includeLockedLayersForFind = false;
                 app.findChangeTextOptions.includeLockedStoriesForFind = false;
                 app.findChangeTextOptions.includeMasterPages = false;
                 app.findChangeTextOptions.wholeWord = true;
                
                 myFoundItems = myFoundItems.concat(searchin.findText()); //.push(myNewFoundItems.slice(0, myFoundItems.length-1));
            }
            // Function By Dave Saunders - http://jsid.blogspot.com
            function zoomObject(theObj) {
            try {
              var objBounds = theObj.geometricBounds;
            } catch (e) {
              throw "Object doesn't have bounds."
            }
            var ObjHeight = objBounds[2] - objBounds[0];
            var ObjWidth = objBounds[3] - objBounds[1];
            var myWindow = app.activeWindow;
            var pageBounds = myWindow.activePage.bounds;
            var PgeHeight = pageBounds[2] - pageBounds[0];
            var PgeWidth = pageBounds[3] - pageBounds[1];
            var hRatio = PgeHeight/ObjHeight;
            var wRatio = PgeWidth/ObjWidth;
            var zoomRatio = Math.min(hRatio, wRatio);
            app.select(theObj); // to make active the page that holds theObj
            myWindow.zoom(ZoomOptions.fitPage);
            myWindow.zoomPercentage = myWindow.zoomPercentage * zoomRatio;
            exit() // Because there's no point in doing this if you don't exit to let the user see
            }

            • 3. Re: InDesign Profanity check
              Thomas B. Nielsen Level 3

              What kind of summary would you like?

               

              Also be aware that the script has yet another issue, is that if you change a word, it will still be in the "words to change array".

              You could make some function to remove the currently selected word from list and select next. Then you would only have the words that needed revision in the list.

               

              --

               

              Thomas B. Nielsen

              http://www.lund-co.dk

              • 4. Re: InDesign Profanity check
                MikeBrog Level 1

                I think this will still be OK for our purposes.  Scripting around this problem is beyond my abilities at this point.

                 

                I was just thinking that it would be nice is a list would appear that would give the number of times the word was found and on what pages.  Expounding on that, it might be nice to use the list to navigate to the occurrence of the words which would also allow you to ignore the separate words in the list that you know are acceptable.

                 

                I know I can't write something this elaborate, but I don't expect anyone else to do it for me, either.

                 

                Thanks again!