Skip to main content
jimelevens
Inspiring
July 5, 2017
Answered

Script to add a bookmark to every page

  • July 5, 2017
  • 2 replies
  • 7361 views

My javascripting has come on a long way recently, creating buttons, adding images etc, but I am totally stumped.

I have been trying for a while to create a script to add a bookmark to every page within an Indesign document to use in go to destination buttons. I can create these manually, but that is not time efficient when you have to 100+. I haver found script that add to paragraph etc. but not the page. I am totally stumped, I planned to place the add bookmark script within a loop like this:

var myDoc = app.activeDocument;

var myDocL = myDoc.pages.length;

for (i=0; i<myDocL; i++){

}

Any help would be greatly appreciated

Correct answer jakec88782761

try this:

var doc = app.activeDocument;

var pages = doc.pages.everyItem().getElements();

addBookmark ( pages );

function addBookmark (destination) {

  

    for ( var i = 0; i < destination.length; i++ ) {

        

    myBookmark = doc.bookmarks.add ( destination );

    myBookmark.name = destination.name;

  

    }

}

2 replies

Participant
June 20, 2023

Great post! I had written a script to add bookmarks based on a list of desired bookmark names and pages but I was getting the "every other name" bug. After finding this thread I closed bookmarks panel and my script worked perfectly.

Community Expert
June 20, 2023

Hi @1234wqesfdc ,

so the bug is still there...

What's your exact version of InDesign on what version of OS?

 

Thanks,
Uwe Laubender
( Adobe Community Expert )

Participant
June 20, 2023

I tested 2 systems and the problem happens on both. Every other (alternating) bookmark name is wrong if script is run with bookmarks panel is open. Close panel, script runs fine. 
Windows 10, InDesign 18.2.1

Mac OS 10.14.4, InDesign 14.0.2

jakec88782761Correct answer
Inspiring
July 5, 2017

try this:

var doc = app.activeDocument;

var pages = doc.pages.everyItem().getElements();

addBookmark ( pages );

function addBookmark (destination) {

  

    for ( var i = 0; i < destination.length; i++ ) {

        

    myBookmark = doc.bookmarks.add ( destination );

    myBookmark.name = destination.name;

  

    }

}

Inspiring
July 5, 2017

destination is a page object, so if you want to change the name of the bookmark go to InDesign ExtendScript API (12.0).

This a a great resource from Jongware. Use it to change the name property to something else.

jimelevens
Inspiring
July 5, 2017

Thanks Jake, that worked, brilliant. I do struggle to understand where to start, I'm new to Javascript. I have been fine adding shapes and images, but this was a step to far for me, thanks for the Jongware link, I have been using that loads, very useful.

I am getting one issue though, it seems to not want to name some of the bookmarks, just leaves them as Bookmark 1, see image, it's not a big problem though.