4 Replies Latest reply on Dec 18, 2008 1:33 AM by (Eugene_Tyson)

    Align Text in a column

      I was wondering if it is possible to create a script that will align a heading depending on if it's in a left hand column or a right hand column. I have text that flows in from a source file, it all comes in fine to a single frame with 2 columns. Each heading has a Keep Option to Start in a New Column. I need the heading in the left column to be always aligned left. And I need the heading in the right column to be always aligned to the right. It's for a book and the usual facing pages apply, single text frame, 2 columns. Is it possible to have a script that only targets a paragraph heading that is in a right column?

      Any help is greatly appreciated, I can honestly say I don't know anything about scripting, I just need this for a current project and InDesign doesn't allow alignment for "Align away from gutters" unfortunately.

        • 1. Re: Align Text in a column
          Level 1
          How does a script know that a paragraph is a heading? Are they only at the top of a column? Are they always at the top of a column -- that is, if it's at the top of a column, it's a heading.

          If so, then this is fairly easy to script. I think the script would just visit every text column in the selected story and set the top-paragraph to align left or right accordingly.

          But wait, what is the parent of a text column? If it's the story, then you'd have to compare the index of the text column with the index of the text of the parent text frame. If they're the same, align left; else align right.

          • 2. Re: Align Text in a column
            Level 1
            This seems to do the job, assuming I've understood correctly:
            //DESCRIPTION: Align headings at tops of columns

            (function() {
              if (app.documents.length > 0 &&
                    app.selection.length == 1 &&
                      app.selection[0].hasOwnProperty("parentStory")) {
                var aStory = app.selection[0].parentStory;
                var textColumns = aStory.textColumns;
                for (var j = textColumns.length - 1; j >= 0; j--) {
                  if (textColumns[j].index != textColumns[j].parentTextFrames[0].texts[0].index) {
                    // column is on right side of frame
                    textColumns[j].paragraphs[0].justification = Justification.rightAlign;
                  } else {
                    // column is on left side of frame
                    textColumns[j].paragraphs[0].justification = Justification.leftAlign;
            I wrote and tested it for CS4, but I expect it works with any version from CS2 on.

            • 3. Re: Align Text in a column
              Level 1
              Thank you so much Dave. That is wonderful. The only problem I had was that it said too many closing braces on line 17. So I removed each brace and saved until it worked. I just removed line 16 brace, line 17 brace and the parenthesis and it works just fine in CS3.

              That is fantastic, I can't thank you enough.
              • 4. Re: Align Text in a column
                Level 1
                Oh, I posted a message after the questions you posed Dave, but they didn't show up, I was having trouble remembering my password as I wasn't on my own machine when writing the reply.

                But many thanks, you understood the question perfectly and it's a wonderful little script.

                Thank you so much