3 Replies Latest reply on May 4, 2011 11:54 AM by Harbs.

    Automating Process with Scripts

    BenMajor Level 1

      Hello all,

       

      I am a seasoned JavaScript programmer, and am currently working on a project which requires a lot of work, and I'm hoping that the process can be automated using scripts for InDesign.

       

      Essentially, here's what I want to do. I have a 5 (sometimes, but rarely, 4)-digit string. I then have three rectangles underneath the text frame which I would like to apply a swatch to, depending on the final digits of the number. Numbers 0-9 are assigned a specific colour (and swatch), and at the moment I am manually going through each rectangle, and selecting it according to the last two digits, and applying the swatch to all those selected.

       

      I am convinced that it must be possible to automate the process using InDesign User Scripts, but I don't have a good understanding of this. Here's an example of how the colours are assigned to the special bar codes:

       

      0 = red 1 = blue 2 = green ....

       

      So for the following code: 12312, I would like the bars underneath to have the following colours:

      blue red blue

      (i.e. top and bottom row = penultimate digit; middle row = last digit).

       

      Could anyone indicate to me how I might write a script which loops through the pages in my document, finds the codes, extracts the last two digits and then applies a swatch to the rectangle object, depending on the number...

       

      I am confident that I could write something like this using regular JavaScript and HTML, but that having been said, I am familiar with the DOM in HTML...

      Any help or pointers would be gratefully received!

       

      Thanks,

      Ben.