Skip to main content
Participant
February 9, 2020
Answered

Script to go to first page

  • February 9, 2020
  • 1 reply
  • 2081 views

Hello,

Can someone please help with a script that I can apply to a book which will leave each document on the 1st page?

Thanks in advance.

This topic has been closed for replies.
Correct answer brian_p_dts

Thanks - that works for the active doc.

Please show me how to insert your script into the following so that it applies to all docs in the book:

var myBook = app.activeBook;
for(var n=0; n < myBook.bookContents.length; n++)
{
app.open(File(myBook.bookContents[n].fullName.toString()));
for (var i = 0; i < app.activeDocument.allPageItems.length; i++)
{
var myPageItem = document.allPageItems[i];
if(myPageItem.getElements()[0].constructor.name == "TextFrame")
{
myPageItem.select();
try{
app.scriptMenuActions.itemByID(71442).invoke();
}catch(e){}
}
}
}


Just throw the select() function before the end of your outer for loop, like so: 

 

var myBook = app.activeBook;
for(var n=0; n < myBook.bookContents.length; n++)
{
app.open(File(myBook.bookContents[n].fullName.toString()));
for (var i = 0; i < app.activeDocument.allPageItems.length; i++)
{
var myPageItem = document.allPageItems[i];
if(myPageItem.getElements()[0].constructor.name == "TextFrame")
{
myPageItem.select();
try{
app.scriptMenuActions.itemByID(71442).invoke();
}catch(e){}
}

}

app.activeDocument.pages[0].select();

}

1 reply

Dave Creamer of IDEAS
Community Expert
Community Expert
February 9, 2020

Can you give more info?

First page of the book or each document in the book? 

What is your output--PDF?

Are you looking a button or something that the user can click to go to the first page?

Do you just want the PDF just to open on a particular page?

David Creamer: Community Expert (ACI and ACE 1995-2023)
Participant
February 10, 2020

It's completely unrelated to the PDF - purely for convenience with the book docs.

I currently use a script which updates all TOCs in the book documents - it's great but it leaves each document on the last master page.

So I want to either add to the end of the TOC script or use a separate one that will bring each document in the book to the first "real" page.

Thanks.

brian_p_dts
Community Expert
Community Expert
February 10, 2020

So if I understand correctly, the script leaves you with the last master page active? Use LayoutWindow or select() to get back to the first page, depending on your needs: 

 

app.layoutWindows[0].activePage = docRef.pages[0];
 
or 
 
docRef.pages[0].select();