7 Replies Latest reply on Jul 28, 2013 3:10 PM by Daniel Swanson

    How I generate index markers using Applescript and tagged text!

    Daniel Swanson Level 1

      One of the challenges I've faced in automating the book making process using Applescript with inDesign is that there don't seem to be any AS commands for making new index markers (anyone please correct me I if I'm wrong about this).

       

      I've tried various js scripts which do an OK job, but they don't make the actual native markers. This means you have to wait until the book (consistiing of multiple ID files) is complete (so that all the page numbers have been established) to generate the index.

       

      Recently, I read a tweet from someone with a link to a technique which uses tagged text and find and replace with GREP to edit the tags, inserting the tagged text index tags in the text file and then re-placing the text file in the ID page. In itself, this works great. But I'm dealing with literally thousands of separate text frames, none of them connected in a story.

       

      The books typically consist of around 1200 pages with almost that many people, each of whose names I need to index with "Lastname, Firstname" references. And those particular strings don't (can't) appear anywhere on the pages. There will also be about 50 ID files all combined into one book. So it is imperative that I have ID generate the native index markers. To help keep things straight and efficient, I'm creating separate small text frames to hold the lastname, firstname strings. I created an object style for these frames which sets the attributes to "nonprinting", and I place the frames in the margin.

       

      Then I realized that I don't actually have to have ID export the tagged text files for each. I exported one prototype and copied its tags to properties in my script, and then I concatenate them with the respective list item values I import from the database.

       

      At the proper point in the page building script, I tell "textwrangleer" to make a new document, set its contents to the index string for the current record, save it to disk, overwriting the previous one, and then tell ID to "place" it in the index text frame, which generates the ID index mark.

       

      I actually got an AS error when I first tried this: "file doesn't exist" or some such. Then I realized that the "place" command was happening too soon, so I inserted a .5 sec delay in the script, and it worked.

       

      This is actually my first major script for actual work, and I'm so excited about it! I promises to cut production time down to about a thenth of what it was.

       

      I still have to add some logic to branch between handlers with slightly different parameters for five different page formats, but the same page building handler will work on all of them.

        • 1. Re: How I generate index markers using Applescript and tagged text!
          L. Guy O'Rojo Level 2

          I do similar projects using a FileMaker database to generate tagged text files for the people pages. The corresponding alphabetical index is generated from the database as well, because the lastname, firstname format is another field in the database.

          • 2. Re: How I generate index markers using Applescript and tagged text!
            Daniel Swanson Level 1

            Thanks for the input, Guy! It gives me some ideas.

             

            I use QSA Toolworks' Helix for my dbms. It's very object oriented and non-procedural. qsatoolworks.com

            • 3. Re: How I generate index markers using Applescript and tagged text!
              [Jongware] Most Valuable Participant

              A note on this:

               

              Daniel Swanson wrote:

               

              I've tried various js scripts which do an OK job, but they don't make the actual native markers. This means you have to wait until the book (consistiing of multiple ID files) is complete (so that all the page numbers have been established) to generate the index.

               

              These scripts typically search for words and immediately write out the page numbers they are found on -- one shot indexing.

               

              The solution is to add both the topic and its page reference to the current document's index:

               

              if (app.activeDocument.indexes.length == 0)
                  app.activeDocument.indexes.add();
              app.activeDocument.indexes[0].topics.add(app.selection[0].contents).pageReferences.add(app.selection[0]);
              

               

              The first lines only make sure there is an index to add to (per default, a new document has none).

               

              The last line adds a selected word to the index (it must be a plain text string, hence the use of its 'contents'), and then adds a reference to the selection in the text itself.

               

              Adding the same word a second time will for a change (quite untypically for ID's Scripting) not result in an error but simply add another page reference to the existing one.

               

              When doing this in a loop: remember to work backwards, because the index marker itself gets inserted into the running text, and that will throw off your text indices.

              • 4. Re: How I generate index markers using Applescript and tagged text!
                Daniel Swanson Level 1

                Thanks, but I'm not using js scripts now that I've got exactly what I want through placing inDesign tagged text as well as Applescript.

                 

                BTW Mr. O'Rojo's input inspired me to use the tagged text feature to set an italics character style to the numerous publication titles which appear in the book. It works great.

                • 5. Re: How I generate index markers using Applescript and tagged text!
                  L. Guy O'Rojo Level 2

                  Always wanted to try Helix. Theoretically it sounds good, especially if it works with Applescript as well as FileMaker. For structured InDesign documents I don't see how anyone can work effectively without a database. You can email me w any questions at lguyorojo at g mail.

                  • 6. Re: How I generate index markers using Applescript and tagged text!
                    Daniel Swanson Level 1

                    It's been a long, long torturous road for Helix, and I've traveled it since about 1987. For me, it's been well worth the ride as I've used it extensively throughout these many years. Its language is very different: graphical UI, drag and drop. Some are put off by its lack of any procedural functions, but on the OOP side, it excels. It's very easy to add relations (tables) and hook them into the overall collection.

                     

                    qsatoolworks.com just released Helix 6.2 for OS X. After having to run previous versions in OS 9 only, while OS X progressed all the way up to Mountain Lion, it's SO NICE to see it run in X! Did you know the original code was written in Pascal?! They had a ton of work to do on a shoestring for years.

                     

                    As I type this, I'm finishing up my Applescript with logic to switch between page layouts based on record categories, and I'm trimming up my handlers as I go. Very excited to have my first major production script fully operational!

                     

                    Message was edited by: Daniel Swanson

                    • 7. Re: How I generate index markers using Applescript and tagged text!
                      Daniel Swanson Level 1

                      Well, I did it. My Applescript script is running! It's knocking out pages like gangbusters from data that came from the customer as a 50-column spreadsheet and about 1300 rows.

                       

                      It's an uncommon pleasure to sit and watch those pages build, pocketa, pocketa, pocketa.

                       

                      The customer will be editing the native inDesign pages using inCopy. So now I'm going to have to write a script to harvest the edits back into the database. I can't parse it field for field, as there are a number of text concatenations throughout. But I will export the respective text frames in inDesign tagged text format and then storing those in their respective document fields for each record in the database. This will enable me to both preserve the edits and to re-generate the pages in case there are any record deletions and/or additions. Where the edit text files exist, I'll simply have Applescript place them back into the respective text frames, thereby preserving any text formatting.

                       

                      It has been a long-time dream of mine to be able to do this kind of work. It's one important type of work at which computers excel.

                       

                      This script and versions of it for other similar jobs will make us 100 times more productive and open up new markets for us.

                       

                      I'm grateful to Apple and Adobe for keep this functionality working welll in their software tools.