12 Replies Latest reply on Apr 3, 2011 7:53 AM by Tom Tomasko

    Confusion of Interpreters

    Tom Tomasko Level 1

      Hello,

       

      I recently wrote a script for a friend that includes a GREP function. When she ran it she got an error message that ends with:

       

      Interpreter: CS2 (4.0)

       

      That explains why there is an error because there was no GREP option in the Find/Change dialog way back in the CS2 days.

       

      However, she is using CS3. How could there be a different interpreter?

       

      Has anybody run into this problem before? How does one set the correct interpreter or get rid of the old one? Any advice would be appreciated.

       

      Thanks,

      Tom

        • 1. Re: Confusion of Interpreters
          John Hawkinson Level 5

          It almost always helps to post your script. The version of the script DOM that is used to interpret your script is set by either the #target directive or by

          app.scriptPreferences.version, as discussed in the Script Versioning section of chapter 2 of the InDesign Scripting Guide.

           

          There is occasionally confusion between the version number and the CS number, so make sure you're right. CS5 is Version 7.0, and CS3 is Version 5.0, etc.

          1 person found this helpful
          • 2. Re: Confusion of Interpreters
            Tom Tomasko Level 1

            Below is the script. I have never set the app.scriptPreferences.version in any script. never thought I had to.

             

            var myDoc = app.activeDocument;
            var discrecHyphen = theGrepChanger(myDoc,"~-","");    

            if(discrecHyphen.length > 0){
                 alert("I just deleted "+discrecHyphen.length+" discretionary hyphens.");
                 }//end if
            else{
                 alert("There were no discretionary hyphens in this document.");
                 }//end else

            //*****functions*******
            function theGrepChanger(docRef,grepFindIt,grepChangeIt){
                 app.findGrepPreferences = NothingEnum.NOTHING;
                 app.changeGrepPreferences = NothingEnum.NOTHING;
                 app.findGrepPreferences.findWhat = grepFindIt;
                 app.changeGrepPreferences.changeTo = grepChangeIt;
                 var arrGrepFindIt = myDoc.changeGrep();
                 return arrGrepFindIt;
            }//end theGrepFinder
            • 3. Re: Confusion of Interpreters
              Harbs. Level 6

              Someone probably changed the script versioning on you...

               

              Put this at the beginning of your script:

               

              app.scriptPreferences.version = app.version;

               

              Harbs

              1 person found this helpful
              • 4. Re: Confusion of Interpreters
                John Hawkinson Level 5

                Sadly it looks you probably need it to be a little uglier:

                 

                app.scriptPreferences.version=app.version.split(".").slice(0,2).join(".")

                 

                Since otherwise you get versions like 6.0.6.622 when you need versions like 6.0.

                • 5. Re: Confusion of Interpreters
                  Tom Tomasko Level 1

                  If I know that the users of the script will only have CS3 why not just write:

                   

                  app.scriptPreferences.version = 5.0;

                   

                  Tom

                  • 6. Re: Confusion of Interpreters
                    John Hawkinson Level 5

                    Sure, you can, it'll work.

                     

                    But you don't know that, and you won't want to deal with it two years later when they upgrade.

                    • 7. Re: Confusion of Interpreters
                      Harbs. Level 6

                      I'm pretty sure what I wrote works, but at the worst it'll be:

                       

                      app.scriptPreferences.version = parseFloat(app.version);

                       

                      Harbs

                      • 8. Re: Confusion of Interpreters
                        John Hawkinson Level 5

                        Yeah, that's much better. I did actually try your initial suggestion, just for fun (not that I'm having this problem) and it threw an error.


                        • 9. Re: Confusion of Interpreters
                          Harbs. Level 6

                          Tom Tomasko wrote:

                           

                          If I know that the users of the script will only have CS3 why not just write:

                           

                          app.scriptPreferences.version = 5.0;

                           

                          Tom

                          Except that might break things when they upgrade in the future...

                           

                          Harbs

                          • 10. Re: Confusion of Interpreters
                            Mayhem SWE Level 2

                            Harbs. wrote:

                             

                            Except that might break things when they upgrade in the future...

                            Uhh, would it not be more future-proof to specify which version your script is targetting rather than rely on 100% backwards compatibility for all eternity? I'd certainly assume so at least...

                            • 11. Re: Confusion of Interpreters
                              John Hawkinson Level 5

                              Err, it's critical that your script not change app.scriptPreferences.version without changing it back.

                               

                              That's how we got in this mess.

                               

                              Everybody writes scripts that ignore app.scriptPreferences.version and they expect to get the current version of the scripting DOM.

                              If for some reason you need an older version, that's fine, but you need to set it back when you're done.

                               

                              I can't decide which of these paradigms is better for that case:

                               

                              function main() {
                                var oldv = app.scriptPreferences.version;
                                app.scriptPreferences.version = 5.0; // I need the CS3 DOM
                              
                                // do stuff here
                              
                                app.scriptPreferences.version = oldv;
                              }
                              main();
                              

                               

                              or

                               

                              function main() {
                                app.scriptPreferences.version = 5.0 // I need the CS3 DOM
                              
                                // do stuff here
                              
                                app.scriptPreferences.version = parseFloat(app.version);
                              }
                              main();
                              

                               

                              but the reason we're in this fix is someone set the script version and didn't set it back. That's not OK. And it's also not OK for every script everyone writes to have to deal with the case of broken scripts that have done that...

                               

                              So, by all means, set the scriptPrefernces version to the current version if you like in your scripts, as long as you set it back at the end. But if you're fixing your script to clean up after someone else's broken script, because of a special case like this, make sure you clean it up to the current version, so everyone else's scripts benefit too.

                              • 12. Re: Confusion of Interpreters
                                Tom Tomasko Level 1

                                Thanks everyone for your replies. They were very helpful.

                                 

                                I recently figured out why the problem existed in the first place. My friend who is using the script never had CS2 so it may no sense to me that the script would invoke the CS2 interpreter. But she has been using some scripts originally designed for CS2 and put them in a "subfolder of our User scripts named Version 4." CS3 uses a folder called Version 5.

                                 

                                So until I used the advice above, a script that did not have a scriptPreferences of version 5.0 would revert to version 4.0.

                                 

                                Tom