5 Replies Latest reply on Oct 10, 2011 10:10 AM by ScribeTypesetDept

    Applescripts Won't Run in CS5

    ScribeTypesetDept

      My applescripts, which worked in CS4, do not work in CS5.

       

      Below is the content of one, which counts the characters in an open document. Instead of running, it opens the script editor. When I click on  the green triangle ("start running the scrpt"), it highlights the line that says "var doc = app.documents.everyItem; //Gets list of all open documents" in orange.

       

       

       

      //===============================================================

      // Name: CharCountOpenDocs

      // Description: Counts all open documents in InDesign

      //

      // Modification Log

      // 100816~aab~Created script from CharCount.jsx

      //===============================================================

       

      var k, h; //K is the counter for all of the documents, H counts each document

      var doc = app.documents.everyItem; //Gets list of all open documents

      var docList = app.documents.length; //Checks to see how many docs are open if 0 closes

      if (docList == 0) { //If there are no open documents, shuts down the script

        alert("There are no open documents.");

        exit();

      }

       

      k = 0; //Sets K to zero before we start counting

      for (i = 0; docList > i; i++) { //This loops through all of the open documents one at a time

          var myDoc = app.documents.item(i); //Takes each doc in list and works on it one at a time

          h = 0; // Sets document counter to zero.

          for (var j = 0; myDoc.stories.length > j; j++) { //Loops through each story (text chain)

              h = myDoc.stories[j].characters.length + h //Gets character count of each story

          }

          k = k + h; //Adds this document to the main counter

          //alert("You have " + h + " characters in this document" ) //Throws an alert for each document

      }

       

      alert("You have " + k + " characters in all open documents" ) //Throws final alert for all documents

        • 1. Re: Applescripts Won't Run in CS5
          Muppet Mark Level 5

          This is NOT AppleScript… but perhaps you should look at JavaScript and how to version scripts… may be that will resolve your issue…

          • 2. Re: Applescripts Won't Run in CS5
            absqua Level 4

            The line that errors:

             

            var doc = app.documents.everyItem; //Gets list of all open documents
            

             

            Should be:

             

            var doc = app.documents.everyItem(); //Gets list of all open documents
            

             

            (Note function-invoking parentheses after "everyItem".)

             

            I don't know how that ever worked in CS4 either without the parentheses. You don't need the line anyway, if this is the entire script; that variable is never used.

             

            Jeff

            • 3. Re: Applescripts Won't Run in CS5
              ScribeTypesetDept Level 1

              Hmm. That didn't work. It highlights that same line and then doesn't do anything. I think issue is beyond my scope to figure out. I just can't get any applescript or javascript to run in CS5, whether it's one created within my company or one I downloaded from the internet. -- thanks for replying.

              • 4. Re: Applescripts Won't Run in CS5
                absqua Level 4

                I now realize I was misguided in my first post. Because that variable is never used, the fact that it referred to a function rather than the result of a function wouldn't have caused an error.

                 

                Try making sure the target dropdown in the ESTK is set to "Adobe InDesign CS5" rather than "ExtendScript Toolkit CS5" and run it again from there.

                 

                Also, where were you originally running the script from? It sounds like maybe you double-clicked it in the Finder rather than double-clicking it in the Scripts palette.

                • 5. Re: Applescripts Won't Run in CS5
                  ScribeTypesetDept Level 1

                  absqua - thank you so much. You're absolutely right. I changed the target dropdown menu, and the script then ran correctly. Hopefully that's all I'll need to do for my other ones...