2

I want to select all text frames and then ALIGN its content to the right of the page of all the ODD numbered pages of my document in InDesign using only Javascript.

here's my progress so far and I know I can determine the odd numbers but still can't make selecting a page work thus no progress to select its text frames too.

main();
function main() {
  var myDocument = app.documents.item(0);
  var myPage = myDocument.pages.item(0);
  var i = 0;

  for (i = 1; i < myDocument.pages.count(); i = i + 2) {
    \\  select  the page, then find all text frames in that page,  then align right
  }
}

any help is appreciated. thank you.

Yuri Khristich
  • 13,448
  • 2
  • 8
  • 23

2 Answers2

1

Here is a simplest solution:

var pages = app.activeDocument.pages;

for (var i = 1; i < pages.length; i = i + 2) {
    app.select(pages[i].textFrames);
    try {
        app.menuActions.item("$ID/Horizontal Page Align Left").invoke()
    } catch(e) {}
}

It relies on selection objects and invoke the menu action. Sometimes this is not the best idea (that is why try/catch). The solution can be more complicated and robust. It depends on your limitations and additional details.

Update

I didn't get that you need to align CONTENT of the frames rather than the frames. It can be done, but the solution differs for linked and non-linked text frames. Except when one paragraph belongs two neighboring pages.

Yuri Khristich
  • 13,448
  • 2
  • 8
  • 23
1

To get all of the frames on a page:

var myFrames = myDocument.pages[i].textFrames;

Then you can loop through the frames and their paragraphs and apply (use different counter variables, e.g "c" and "b")

myFrames[c].paragraphs[b].justification = Justification.RIGHT_ALIGN;

You can also try everyItem()

myDocument.pages[i].textFrames.everyItem().paragraphs.everyItem().justification = Justification.RIGHT_ALIGN;
Nicolai Kant
  • 1,391
  • 1
  • 9
  • 23