Skip to main content
Participant
November 17, 2010
Question

looking to hyperlink two character styles

  • November 17, 2010
  • 1 reply
  • 707 views

I'm very new to scripting and even the concept of using scripts. I've got InDesign CS4. I have several documents with endnotes (some with as many as 130). I'm working on exporting them all as ePub files. I've already got all of their numbers and the footnote numbers in the text assigned to a specific character style. What I'm wondering is if it is possible to create a script to link each instance of one character style to its corresponding number in another character style, or does anyone know of a script that has already been created to do this?

As an example, it would find all of the numbers that have been assigned a character style of "footnote" in the text and link them to the same numbers (1 to 1, 2 to 2, etc.) with the character style "footnote destination". The end product then would allow a user to click on a footnote number, be taken to the note, then click on that note's number and be taken back to where they left off in the book.

Any ideas?

Rob

This topic has been closed for replies.

1 reply

Jongware
Community Expert
Community Expert
November 17, 2010

Piece of cake.

That is, I get errors when I try to run this script twice. I might want to look into fixing that ...

app.findGrepPreferences = null;

app.findGrepPreferences.appliedCharacterStyle = "footnote";

app.findGrepPreferences.findWhat = "\\d+";

sourceList = app.activeDocument.findGrep();

app.findGrepPreferences = null;

app.findGrepPreferences.appliedCharacterStyle = "footnote destination";

app.findGrepPreferences.findWhat = "\\d+";

destList = app.activeDocument.findGrep();

if (sourceList.length != destList.length)

{

     alert ("This doesn't match -- please review\r\rSource: "+sourceList.length+"\rDest: "+destList.length);

     exit(0);

}

for (i=0; i<sourceList.length; i++)

{

     app.activeDocument.hyperlinks.add(app.activeDocument.hyperlinkTextSources.add(sourceList), app.activeDocument.hyperlinkTextDestinations.add(destList));

     app.activeDocument.hyperlinks.add(app.activeDocument.hyperlinkTextSources.add(destList), app.activeDocument.hyperlinkTextDestinations.add(sourceList));

}

Participant
November 18, 2010

Holy Cow, that was awesome! But it stopped at 51 links (up to footnote 26) and gave me this message:

JavaScript Error!

Error Number 79111

Error String: The object you have chosen is alrady in use by another hyperlink.

I believe that have some problem with line 18:

app.activeDocument.hyperlinks.add(app.activeDocument.hyperlinkTextSources.add(sourceList), app.activeDocument.hyperlinkTextDestinations.add(destList));

Any ideas?

Rob

Jongware
Community Expert
Community Expert
November 18, 2010

Yeah -- oddly, that's exactly the error I get after running it twice on a test file -- even when I deleted all hyperlinks I could see.

I have no idea what it's complaining about ... Clearly, there are no hyperlinks in that place before the script adds one, and (also) clearly, it ought to add them only once to both target and destination!

Any suggestions from one of the other guys (& gals) are appreciated