7 Replies Latest reply on Jul 29, 2013 12:34 PM by JoeTrox

    CS6 findchangebuylist with javascript error

    JoeTrox

      Running Mac OS 10.6.8

      iMac 2.93 GHz Intel Core i7

      4GB 1333 MHz DDR3

      Indesign CS6 8.0.1

       

      I have created an new page with nothing on it except a text box. I imported paragraph and text styles for a master page templatre created for a catalog I am creating. I created the new page to try and eliminate any issues that may have been cause by opending an document created in CS5.5. I am using the "recordfindchange" script latest version for cs3-cs5 written by Martin Fisher to export the findchange result of my test. Here is an image of the findchange quire:

      Screen shot 2013-07-26 at 10.05.22 AM.png

      I get a java script error when I run the script I created buy copying the "findchangebylist: javascript and txt file, adding the name _SimpleTest to the file names and replaceing Line number 116 in the javascript with this:

      var myFindChangeFile = myFindFile("/FindChangeSupport/findChangeStrings_SimpleTest")

      Here is the error I get:

      Screen shot 2013-07-15 at 2.21.29 PM.png

      I know nothing about javascript. so I am dead in the water. so can someone please help. Is there any issues with CS6 and the findchangebylist script? does "recordfindchange" no longer work with CS6? Could it be a javascript version problem (I just updated to the latest version)?

        • 1. Re: CS6 findchangebuylist with javascript error
          Peter Spier Most Valuable Participant (Moderator)

          In the original script, line 116 seems to be:

          var myFindChangeFile = myFindFile("/FindChangeSupport/FindChangeList.txt")

           

          You said all you did was add _SimpleTest to the name, but then you went looking for "/FindChangeSupport/findChangeStrings_SimpleTest" which is not the same filename with the added _SimpleText. Is uspect it's a combination of specifying the wrong filename and possibly not including the .txt extension.

          • 2. Re: CS6 findchangebuylist with javascript error
            JoeTrox Level 1

            Sorry I should have included the entire javascript so you could see exactly whats there. I am calling the correct file and I am not including the .txt extension.

            I'll include the findchange.txt file after the javascript.

             

            Here it is Javascript:

             

             

            //FindChangeByList.jsx

            //An InDesign CS6 JavaScript

            /* 

            @@@BUILDINFO@@@ "FindChangeByList.jsx" 3.0.0 15 December 2009

            */

            //Loads a series of tab-delimited strings from a text file, then performs a series

            //of find/change operations based on the strings read from the file.

            //

            //The data file is tab-delimited, with carriage returns separating records.

            //

            //The format of each record in the file is:

            //findType<tab>findProperties<tab>changeProperties<tab>findChangeOptions<tab>description

            //

            //Where:

            //<tab> is a tab character

            //findType is "text", "grep", or "glyph" (this sets the type of find/change operation to use).

            //findProperties is a properties record (as text) of the find preferences.

            //changeProperties is a properties record (as text) of the change preferences.

            //findChangeOptions is a properties record (as text) of the find/change options.

            //description is a description of the find/change operation

            //

            //Very simple example:

            //text    {findWhat:"--"}    {changeTo:"^_"}    {includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, wholeWord:false}    Find all double dashes and replace with an em dash.

            //

            //More complex example:

            //text    {findWhat:"^9^9.^9^9"}    {appliedCharacterStyle:"price"}    {include footnotes:true, include master pages:true, include hidden layers:true, whole word:false}    Find $10.00 to $99.99 and apply the character style "price".

            //

            //All InDesign search metacharacters are allowed in the "findWhat" and "changeTo" properties for findTextPreferences and changeTextPreferences.

            //

            //If you enter backslashes in the findWhat property of the findGrepPreferences object, they must be "escaped"

            //as shown in the example below:

            //

            //{findWhat:"\\s+"}

            //

            //For more on InDesign scripting, go to http://www.adobe.com/products/indesign/scripting/index.html

            //or visit the InDesign Scripting User to User forum at http://www.adobeforums.com

            //

            main();

            function main(){

                var myObject;

                //Make certain that user interaction (display of dialogs, etc.) is turned on.

                app.scriptPreferences.userInteractionLevel = UserInteractionLevels.interactWithAll;

                if(app.documents.length > 0){

                    if(app.selection.length > 0){

                        switch(app.selection[0].constructor.name){

                            case "InsertionPoint":

                            case "Character":

                            case "Word":

                            case "TextStyleRange":

                            case "Line":

                            case "Paragraph":

                            case "TextColumn":

                            case "Text":

                            case "Cell":

                            case "Column":

                            case "Row":

                            case "Table":

                                myDisplayDialog();

                                break;

                            default:

                                //Something was selected, but it wasn't a text object, so search the document.

                                myFindChangeByList(app.documents.item(0));

                        }

                    }

                    else{

                        //Nothing was selected, so simply search the document.

                        myFindChangeByList(app.documents.item(0));

                    }

                }

                else{

                    alert("No documents are open. Please open a document and try again.");

                }

            }

            function myDisplayDialog(){

                var myObject;

                var myDialog = app.dialogs.add({name:"FindChangeByList"});

                with(myDialog.dialogColumns.add()){

                    with(dialogRows.add()){

                        with(dialogColumns.add()){

                            staticTexts.add({staticLabel:"Search Range:"});

                        }

                        var myRangeButtons = radiobuttonGroups.add();

                        with(myRangeButtons){

                            radiobuttonControls.add({staticLabel:"Document", checkedState:true});

                            radiobuttonControls.add({staticLabel:"Selected Story"});

                            if(app.selection[0].contents != ""){

                                radiobuttonControls.add({staticLabel:"Selection", checkedState:true});

                            }

                        }           

                    }

                }

                var myResult = myDialog.show();

                if(myResult == true){

                    switch(myRangeButtons.selectedButton){

                        case 0:

                            myObject = app.documents.item(0);

                            break;

                        case 1:

                            myObject = app.selection[0].parentStory;

                            break;

                        case 2:

                            myObject = app.selection[0];

                            break;

                    }

                    myDialog.destroy();

                    myFindChangeByList(myObject);

                }

                else{

                    myDialog.destroy();

                }

            }

            function myFindChangeByList(myObject){

                var myScriptFileName, myFindChangeFile, myFindChangeFileName, myScriptFile, myResult;

                var myFindChangeArray, myFindPreferences, myChangePreferences, myFindLimit, myStory;

                var myStartCharacter, myEndCharacter;

                var myFindChangeFile = myFindFile("/FindChangeSupport/findChangeStrings_SimpleTest")

                if(myFindChangeFile != null){

                    myFindChangeFile = File(myFindChangeFile);

                    var myResult = myFindChangeFile.open("r", undefined, undefined);

                    if(myResult == true){

                        //Loop through the find/change operations.

                        do{

                            myLine = myFindChangeFile.readln();

                            //Ignore comment lines and blank lines.

                            if((myLine.substring(0,4)=="text")||(myLine.substring(0,4)=="grep")||(myLine.substring(0, 5)=="glyph")){

                                myFindChangeArray = myLine.split("\t");

                                //The first field in the line is the findType string.

                                myFindType = myFindChangeArray[0];

                                //The second field in the line is the FindPreferences string.

                                myFindPreferences = myFindChangeArray[1];

                                //The second field in the line is the ChangePreferences string.

                                myChangePreferences = myFindChangeArray[2];

                                //The fourth field is the range--used only by text find/change.

                                myFindChangeOptions = myFindChangeArray[3];

                                switch(myFindType){

                                    case "text":

                                        myFindText(myObject, myFindPreferences, myChangePreferences, myFindChangeOptions);

                                        break;

                                    case "grep":

                                        myFindGrep(myObject, myFindPreferences, myChangePreferences, myFindChangeOptions);

                                        break;

                                    case "glyph":

                                        myFindGlyph(myObject, myFindPreferences, myChangePreferences, myFindChangeOptions);

                                        break;

                                }

                            }

                        } while(myFindChangeFile.eof == false);

                        myFindChangeFile.close();

                    }

                }

            }

            function myFindText(myObject, myFindPreferences, myChangePreferences, myFindChangeOptions){

                //Reset the find/change preferences before each search.

                app.changeTextPreferences = NothingEnum.nothing;

                app.findTextPreferences = NothingEnum.nothing;

                var myString = "app.findTextPreferences.properties = "+ myFindPreferences + ";";

                myString += "app.changeTextPreferences.properties = " + myChangePreferences + ";";

                myString += "app.findChangeTextOptions.properties = " + myFindChangeOptions + ";";

                app.doScript(myString, ScriptLanguage.javascript);

                myFoundItems = myObject.changeText();

                //Reset the find/change preferences after each search.

                app.changeTextPreferences = NothingEnum.nothing;

                app.findTextPreferences = NothingEnum.nothing;

            }

            function myFindGrep(myObject, myFindPreferences, myChangePreferences, myFindChangeOptions){

                //Reset the find/change grep preferences before each search.

                app.changeGrepPreferences = NothingEnum.nothing;

                app.findGrepPreferences = NothingEnum.nothing;

                var myString = "app.findGrepPreferences.properties = "+ myFindPreferences + ";";

                myString += "app.changeGrepPreferences.properties = " + myChangePreferences + ";";

                myString += "app.findChangeGrepOptions.properties = " + myFindChangeOptions + ";";

                app.doScript(myString, ScriptLanguage.javascript);

                var myFoundItems = myObject.changeGrep();

                //Reset the find/change grep preferences after each search.

                app.changeGrepPreferences = NothingEnum.nothing;

                app.findGrepPreferences = NothingEnum.nothing;

            }

            function myFindGlyph(myObject, myFindPreferences, myChangePreferences, myFindChangeOptions){

                //Reset the find/change glyph preferences before each search.

                app.changeGlyphPreferences = NothingEnum.nothing;

                app.findGlyphPreferences = NothingEnum.nothing;

                var myString = "app.findGlyphPreferences.properties = "+ myFindPreferences + ";";

                myString += "app.changeGlyphPreferences.properties = " + myChangePreferences + ";";

                myString += "app.findChangeGlyphOptions.properties = " + myFindChangeOptions + ";";

                app.doScript(myString, ScriptLanguage.javascript);

                var myFoundItems = myObject.changeGlyph();

                //Reset the find/change glyph preferences after each search.

                app.changeGlyphPreferences = NothingEnum.nothing;

                app.findGlyphPreferences = NothingEnum.nothing;

            }

            function myFindFile(myFilePath){

                var myScriptFile = myGetScriptPath();

                var myScriptFile = File(myScriptFile);

                var myScriptFolder = myScriptFile.path;

                myFilePath = myScriptFolder + myFilePath;

                if(File(myFilePath).exists == false){

                    //Display a dialog.

                    myFilePath = File.openDialog("Choose the file containing your find/change list");

                }

                return myFilePath;

            }

            function myGetScriptPath(){

                try{

                    myFile = app.activeScript;

                }

                catch(myError){

                    myFile = myError.fileName;

                }

                return myFile;

            }

             

             

             

            Here  is the File "findChangeStrings_SimpleTest.txt"

             


            //FindChangeList.txt

            //A support file for the InDesign CS4 JavaScript FindChangeByList.jsx

            //

            //This data file is tab-delimited, with carriage returns separating records.

            //

            //The format of each record in the file is:

            //findType<tab>findProperties<tab>changeProperties<tab>findChangeOptions<tab>description

            //

            //Where:

            //<tab> is a tab character

            //findType is "text", "grep", or "glyph" (this sets the type of find/change operation to use).

            //findProperties is a properties record (as text) of the find preferences.

            //changeProperties is a properties record (as text) of the change preferences.

            //findChangeOptions is a properties record (as text) of the find/change options.

            //description is a description of the find/change operation

            //

            //Very simple example:

            //text    {findWhat:"--"}    {changeTo:"^_"}    {includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, wholeWord:false}    Find all double dashes and replace with an em dash.

            //

            //More complex example:

            //text    {findWhat:"^9^9.^9^9"}    {appliedCharacterStyle:"price"}    {include footnotes:true, include master pages:true, include hidden layers:true, whole word:false}    Find $10.00 to $99.99 and apply the character style "price".

            //

            //All InDesign search metacharacters are allowed in the "findWhat" and "changeTo" properties for findTextPreferences and changeTextPreferences.

            //

            //If you enter backslashes in the findWhat property of the findGrepPreferences object, they must be "escaped"

            //as shown in the example below:

            //

            //{findWhat:"\\s+"}

            //

            grep    {findWhat:"  +"}    {changeTo:" "}    {includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, wholeWord:false}    Find all double spaces and replace with single spaces.

            grep    {findWhat:"\r "}    {changeTo:"\r"}    {includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, wholeWord:false}    Find all returns followed by a space And replace with single returns.

            grep    {findWhat:" \r"}    {changeTo:"\r"}    {includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, wholeWord:false}    Find all returns followed by a space and replace with single returns.

            grep    {findWhat:"\t\t+"}    {changeTo:"\t"}    {includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, wholeWord:false}    Find all double tab characters and replace with single tab characters.

            grep    {findWhat:"\r\t"}    {changeTo:"\r"}    {includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, wholeWord:false}    Find all returns followed by a tab character and replace with single returns.

            grep    {findWhat:"\t\r"}    {changeTo:"\r"}    {includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, wholeWord:false}    Find all returns followed by a tab character and replace with single returns.

            grep    {findWhat:"\r\r+"}    {changeTo:"\r"}    {includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, wholeWord:false}    Find all double returns and replace with single returns.

            text    {findWhat:" - "}    {changeTo:"^="}    {includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, wholeWord:false}    Find all space-dash-space and replace with an en dash.

            text    {findWhat:"--"}    {changeTo:"^_"}    {includeFootnotes:true, includeMasterPages:true, includeHiddenLayers:true, wholeWord:false}    Find all dash-dash and replace with an em dash.

             

            //The test starts here

            grep    {, findWhat:"\\r\\r.+[:].+\\r"}    {, appliedParagraphStyle:"01-Header"}    {includeLockedStoriesForFind:false, includeLockedLayersForFind:false, includeHiddenLayers:true, includeMasterPages:true, includeFootnotes:true, kanaSensitive:true, widthSensitive:true}    //Comment

            • 3. Re: CS6 findchangebuylist with javascript error
              Peter Spier Most Valuable Participant (Moderator)

              try including the .txt extension in the call...

              • 4. Re: CS6 findchangebuylist with javascript error
                JoeTrox Level 1

                Tried that and it doesnt work either. Any other ideas?

                 

                Thanks for your help Peter!

                • 5. Re: CS6 findchangebuylist with javascript error
                  Peter Spier Most Valuable Participant (Moderator)

                  I've moved this over to the scripting forums so you can get some real help from the guys who do this stuff for real.

                  • 6. Re: CS6 findchangebuylist with javascript error
                    JoeTrox Level 1

                    Thanks Peter! Hope someone there knows.

                    • 7. Re: CS6 findchangebuylist with javascript error
                      JoeTrox Level 1

                      It appears that I may have solved my own problem. through much due diligence, I came to the conclusion that whenever you are appling a paragraph or character style you need to include ", changeConditionsMode:1919250519" within your grep. If you look above at the "findChangeStrings_SimpleTest.txt" you will se that this hasn't been added in. as a result you will get a javascript error. Also there is an extra ", " (comma and a space) infront of "findwhat" and "appliedParagraphStyle" I removed those just for consistance. but it appeard to have no effect. 

                      It shhould look like this:

                      {findWhat:"\\r\\r.+[:].+\\r"}{appliedParagraphStyle:"01-Header", changeConditionsMode:1919250519}

                       

                      SO in short it look like the "ChangeCondidtionsMode:1919250519" is the Key to eliminated the javascript error.

                       

                      I don't know why. All I know is now it works.

                       

                      While looking at my findchange.txt file for the project I am working on (not the one above) I also noticed that there we stray characters outside of the "{ }" (brackets). Apparently that was making  indesign CS6 crash. The script that I have been working on was written in CS5.5. That version must have been a little more forgiving with sloppy code. After cleaning all of the random characters up no more crashes.

                       

                      I also upated my CS6 version 8.0 to Version 8.0.1. adobe has a downloadable patch. That may have help the issue as well. It did not however help the missing changeCondidtionsMode or the sloppy code.

                       

                      The RecordFindChange script I have been using doesn't put the "ChangeCondidtionsMode:1919250519" into the exported .txt file and it aslo adds in the extra commas. That will have to be changed by someone that knows javascript and that is not me.

                       

                      Hope this helps.