Create a hyperlink via script to another document in a Book
Hi all,
I have a Book-based project with multiple chapters in individual files, and I'm trying to write a script to turn mentions of particular years into hyperlinks to appropriate chapters, for easy cross-referencing in the final exported PDF. For instance, 1953 -> Chapter17.indd. So far my script successfully finds all the sources I want to link, and is able via a lookup table to convert years to the relevant chapter filenames, but I'm not sure how to then create the right kind of destination link itself in a script.
Manually in InDesign, I could do this by creating a new Hyperlink that links to either a Page (the first page of the relevant chapter), or to a Text Anchor (I can use the TOC anchor at the start of each chapter for this), both of which have drop-downs for selecting the book chapter file first. But I can't figure out how to create this kind of hyperlink via scripting. HyperlinkExternalPageDestination seems like the closest thing from the docs ("a page in a document other than the document that contains the hyperlink source"), so it feels like I should be doing something like this:
app.activeDocument.hyperlinkExternalPageDestinations.add(...);
But add() takes a Page object as its parameter, and I don't know how to get from a filename or path like "Chapter17.indd" to a Page. I thought maybe I might need to use the Book object, and was able to successfully retrieve a BookContent object that matches the right chapter; but I don't see any way in the BookContent spec for me to access Page objects within it either. Any pointers in the right direction would be much appreciated!
