Skip to main content
Participating Frequently
October 29, 2012
Question

script to get the first word on each page

  • October 29, 2012
  • 1 reply
  • 2341 views

Is there a script that would make a list of the first word of each page (or, preferably, create a text box on each page and place the next page's word in that)? My document's all in one story with one text frame on each page, although there are several other frames (header, page number) applied through master pages.

This topic has been closed for replies.

1 reply

Inspiring
October 29, 2012

Something like this, maybe...

if( !(app.selection[0] instanceof InsertionPoint) ) {alert("First, target a story by inserting a blinking cursor."); exit(); }

var stry = app.selection[0].parentStory, d = app.documents[0], i, tf1, tf2, wrd, ntf, bnds, pg, ro = d.viewPreferences.rulerOrigin;

d.viewPreferences.rulerOrigin = RulerOrigin.SPREAD_ORIGIN;

for ( i = stry.textContainers.length - 1; i > 0;  i-- ) {

    tf2 = stry.textContainers;

    wrd = tf2.words[0];

    tf1 = stry.textContainers[i-1];

    pg = tf1.parentPage;

    bnds = pg.bounds;

    ntf = pg.textFrames.add( undefined, undefined, undefined, {geometricBounds:[ bnds[0], bnds[1], bnds[0] + "3p0", bnds[3] ] } );

    ntf.textFramePreferences.verticalJustification = VerticalJustification.BOTTOM_ALIGN;

    wrd.duplicate( LocationOptions.AT_BEGINNING, ntf );

    ntf.texts[0].justification = Justification.CENTER_ALIGN;

}

d.viewPreferences.rulerOrigin = RulerOrigin[ro];

Paul1023Author
Participating Frequently
October 29, 2012

Thanks - it worked great. One follow-up, though - how would I change the position of the new text frames, and make them all linked?

Inspiring
October 29, 2012

geometricBounds controls the size and location of the textframes. Where do you the text to appear?