4 Replies Latest reply on Aug 6, 2009 12:31 AM by dhishok

    dynamic toc style creation & sorting entries...

    dhishok Level 1

      Hi Everyone,


      We have created the batch script to generate artlink reports of multiple inx files in one text file. Finally we have to sort this report in alphabetical order. I have tried with the concept [myArray.sort()] before writing into text file. It is working but it sorts uppercase letters first and then it sorts lowercase letters of each entries. For example,


      Array sortingBut Expecting









      Can anyone look into this and help for me. Or help me for below query.


      We can sort this report perfectly with InDesign TOC options. I have tried to create TOC style through javascript, but i am unable to do that. Can anyone suggest me that how to create TOC style (with one paragraph style and with Sort Entries in Alphabetical order option) or how to import TOC styles from other document through javascript.


      Thanks in advance.




        • 1. Re: dynamic toc style creation & sorting entries...
          [Jongware] Most Valuable Participant

          This is what the JS Help says about Array -> Sort:


          void sort (userFunction: Function)
          Sorts the elements of the array in place, using the given function to compare to elements.
          If no function is provided, the elements are sorted alphabetically. Returns no return value.

          userFunctionFunctionA user-supplied function of the form userFunction(a, b) which returns less than 0 if a is greater than b, 0 if a and b are equal, and greater than 0 if b is greater than a.


          As it says, default behaviour is to sort alphabetically -- and by that, they must mean "in ASCII order". What you need is a custom sort routine. A few string manipulations further, I come to this conclusion:


          var myArray = [
          "candy.tif" ];
          myArray.sort(function (a,b) { return a.toUpperCase() == b.toUpperCase() ? (a < b ? -1 : a > b) : (a.toUpperCase() < b.toUpperCase() ? -1 : a.toUpperCase() > b.toUpperCase()); });
          alert (myArray.join ('\n'));


          which correctly sorts the array case independent.

          • 2. Re: dynamic toc style creation & sorting entries...
            Harbs. Level 6

            The default sort sorts by unicode value.


            FWIW, this is the function I use to do real alphabetical sorting 

            (which is basically the same as Jong's but a whole lot easier to 

            read) :



                 var A = a.toLowerCase();

                 var B = b.toLowerCase();

                 if (A < B) return -1;

                 if (A > B) return 1;

                 if (a < b) return -1;

                 if (a > b) return 1;

                 return 0;



            To use it you do something like this:





            1 person found this helpful
            • 3. Re: dynamic toc style creation & sorting entries...
              [Jongware] Most Valuable Participant

              We great minds think alike -- I wrote up mine from memory, mentally going over the possibilities. Yours does exactly the same. (Readers are invited to comment on why I say it does, as Harbs uses 'tolowercase' where I do 'touppercase'.)

              1 person found this helpful
              • 4. Re: dynamic toc style creation & sorting entries...
                dhishok Level 1

                Hi Jongware & Harbs,


                Thanks for your great and timely support. Both syntaxes are working fine. This is what exactly i have expected. But the difference between this two is,


                According to Jong's syntax the sorting has been done in this order

                (Numbers, alphabets, special characters (underscore & hyphen))

                Refer attached snapshot: Picture1.png


                According to harbs syntax the sorting has been done in this order

                (Numbers, special characters (underscore & hyphen), alphabets)

                Refer attached snapshot: Pcture2.png


                Can you suggest for my below query,

                My script will open each document from the folder and generating the art link reports. From starting to end of process the progress bar window will takes place to show the status of the process. The concern is the progress window has sent to back after opening each document. Is it possbile to minimize the documents window, so the progress bar window only displayed in the screen as front most window.



                Once again i am thanking you.