Thanks JC. I had a bit of brain-fade. Unfortunately being able to do that didn't solve my main problem.
Kasyan Servetsky was kind enough to write me a script to add hyperlinks to page numbers in a concordance. Unfortunately I didn't make clear that many of the page numbers are repeated and thus the script only adds a hyperlink to one instance of a page number. In the script that follows the second and any subsequent occurrence fails at line 43 (source = doc.hyperlinkTextSources.add(sourceTextRef);, or at least in that section. Changing the character style of the non-linked page numbers in the concordance and editing the script got me nowhere. Can anyone modify the following script to overcome the problem?
/* Copyright 2016, Kasyan Servetsky
September 29, 2016
Written by Kasyan Servetsky
//======================================================================================
var set, doc,
count = 0,
scriptName = "Make hyperlinks";
PreCheck();
//===================================== FUNCTIONS ======================================
function Main() {
app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.NOTHING;
app.findGrepPreferences.findWhat = "\\d+";
app.findGrepPreferences.appliedCharacterStyle = "Pg Number";
var foundItems = doc.findGrep(true);
app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.NOTHING;
if (foundItems.length == 0) ErrorExit("No page numbers were found in the current document.", true);
for (var i = 0; i < foundItems.length; i++) {
try {
var sourceTextRef = foundItems[i];
MakeHyperlink(sourceTextRef);
}
catch(err) {
$.writeln(err.message + ", line: " + err.line);
}
}
var report = count + " hyperlink" + ((count == 1) ? " was" : "s were") + " created.";
alert("Finished. " + report, scriptName);
}
//--------------------------------------------------------------------------------------------------------------------------------------------------------
function MakeHyperlink(sourceTextRef) {
var source, destination, hyperlink,
pageNum = sourceTextRef.contents,
obj = GetPage(pageNum);
if (obj != null) {
source = doc.hyperlinkTextSources.add(sourceTextRef);
destination = obj.docDest.hyperlinkPageDestinations.add(
obj.page);
hyperlink = doc.hyperlinks.add(source, destination, {name: "Page_" + pageNum});
if (hyperlink.isValid) {
count++;
}
}
}
//--------------------------------------------------------------------------------------------------------------------------------------------------------
function GetPage(pageNum) {
var obj = null;
for (var i = 0; i < app.documents.length; i++) {
if (app.documents[i].pages.itemByName(pageNum).isValid) {
obj = {page: app.documents[i].pages.itemByName(pageNum), docDest: app.documents[i]};
break;
}
}
return obj;
}
//--------------------------------------------------------------------------------------------------------------------------------------------------------
function PreCheck() {
if (app.documents.length == 0) ErrorExit("Please open a document and try again.", true);
doc = app.activeDocument;
if (!app.activeDocument.saved) ErrorExit("The current document has not been saved since it was created. Please save the document and try again.", true);
Main();
}
//--------------------------------------------------------------------------------------------------------------------------------------------------------
function ErrorExit(error, icon) {
alert(error, scriptName, icon);
exit();
}