Copy link to clipboard
Copied
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
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;
}
}
Copy link to clipboard
Copied
Minor correction to this code to get it to work.
destination needs an array value to work in the loop destination[i]
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[i]);
myBookmark.name = destination[i].name;
}
}
Copy link to clipboard
Copied
Hi @wckdtall ,
thanks for correcting this. The cause of the missing iterator was a switch of forum software some years ago that wrecked a lot of code samples in the forum.
Thanks,
Uwe Laubender
( Adobe Community Expert )
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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 )
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
It's a super basic script. I'll put it here for reference. To test, just make a blank document with at least 3 pages in it and then run the script.
var BMlist=[
["name1",1],
["name2",2],
["name3",3]
];
var mydoc=app.documents[0];
var bmd;//bookmark data pulled from BMlist
var bm;//actual bookmark
for (var i=0; i<BMlist.length; i++){
bmd=BMlist[i];
bm=mydoc.bookmarks.add(mydoc.pages[bmd[1]-1]);
bm.name=bmd[0];
}
Find more inspiration, events, and resources on the new Adobe Community
Explore Now