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.

Community Expert
July 6, 2017

Uwe

I saw the same, stepped through the script in debugging and it looks like it is naming the bookmark but then doesn't show in Indesign. As I said in my previous post I can cope with the name Bookmark1, 2 etc, but it would be nice to sort it.


Jim,

I think, I have an idea where the bug is.

The issues only occured if the Bookmarks Panel is open.

If the panel is closed naming was no problem.

Just tested that with InDesign CS6 v 8.1.0 on OS X 10.6.8.

Nevertheless we should report the bug here:

Wishform - Adobe InDesign

What exact version of InDesign and OS are you using?

Regards,
Uwe