Created
September 15, 2022 12:40
-
-
Save vincenavarro/e425ec43f2001789814d618eef75588e to your computer and use it in GitHub Desktop.
Generate a list of Hyperlinks from an InDesign document
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Original code: https://community.adobe.com/t5/indesign-discussions/script-to-extract-hyperlinks-from-indesign-file-with-page-number/m-p/10754550 | |
Modified to add name and in correct order. | |
Reference: https://www.indesignjs.de/extendscriptAPI/indesign-latest/#Hyperlink.html | |
*/ | |
var list = []; | |
//for (a=0; a<app.activeDocument.hyperlinks.length; a++) | |
for (i = app.activeDocument.hyperlinks.length - 1; i >= 0; i--) | |
{ | |
try | |
{ | |
hypDest = app.activeDocument.hyperlinks[i].destination.destinationURL; | |
if (hypDest.match(/^http/)) | |
{ | |
var hypSource = app.activeDocument.hyperlinks[i].source | |
var hypName = app.activeDocument.hyperlinks[i].name | |
var page | |
if(hypSource.constructor.name == "HyperlinkPageItemSource") | |
page = hypSource.sourcePageItem.parentPage.name | |
else if(hypSource.constructor.name == "HyperlinkTextSource") | |
page = hypSource.sourceText.parentTextFrames[0].parentPage.name | |
$.writeln(page) | |
list.push (hypName + ", Page " + page + ", " + hypDest); | |
} | |
} catch(_) {} | |
} | |
// show the list | |
alert ('All links:\r'+list.join('\r')); | |
// save the list as a file | |
listFile = new File(Folder.myDocuments+"/all_links.txt"); | |
if (listFile.open("w")) | |
{ | |
listFile.writeln(list.join('\n')); | |
listFile.close(); | |
listFile.execute(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment