Copy link to clipboard
Copied
Hi Scripters, big question!!!
With two documents open, I have some hyperlinkTextDestinations previously created by text selections.
Now want to create hyperlinks with hyperlinkTextSources refering to the same text used for anchors.
Trying for hours several solutions and roaming the web with no success, here's a test script:
var myLink = app.documents[0].hyperlinkTextDestinations[0].destinationText.select();
var mySource = app.documents[0].hyperlinkTextSources.add(myLink);
var myAnchor = app.documents[1].hyperlinkTextDestinations[0];
app.documents[0].hyperlinks.add(mySource, myAnchor);
The prob is that i get (line 1) an insertionPoint instead a text selection.
Any indications appreciated,
regards
See here for your answer
Copy link to clipboard
Copied
-- by using apple script -> u converted this into java script
eg : set mydoc to active document -> apple script
var myDoc = app.activeDocument -> java script
select text of selection
set SourceText to item 1 of selection as string
set hrperlnk to hyperlinks
set LnkTxt to 0
set HyperLnkTxt to hyperlink text sources
repeat with i from 1 to count of HyperLnkTxt
set HyperLnkSrc to item i of HyperLnkTxt
set src to contents of source text of HyperLnkSrc
if src is equal to SourceText then
set LnkTxt to 1
set HyperLnkSrc to item i of HyperLnkTxt
exit repeat
end if
end repeat
Copy link to clipboard
Copied
Thank you SuriyaRevathi,
but, if I've right understood your script, a selected text is my target (js line 1) not my starting point (it will be at js line 2)
Copy link to clipboard
Copied
See here for your answer
Copy link to clipboard
Copied
Thanks Trevor,
very useful post confirming that looking for hyperlinkTextDesination it just gets an insertionPoint and not contents.
I need to create bidirectional hyperlinks (text to note, note to text) this is why i want to transform an anchor in a source too.
Now from this Select one or more characters after insertion point (thank you for reply) i will try.
regards
Copy link to clipboard
Copied
Hi Foredit,
Remember you can only create bidirectional hyperlinks if each destination only has one source.
Is that the case by you?
Trevor.
P.s. Please mark the other post as answered.
Copy link to clipboard
Copied
Yes, it is
Thank you Trevor
Copy link to clipboard
Copied
Ok, here's a start ![]()
See before and after screenshots
Read the warning


Click the shots to see them clearly
// Make new bidirectional hyperlinks from existing unidirectional ones
// By Trevor http://forums.adobe.com/thread/1212690?tstart=0
// WARNING ONLY WILL (IF LUCKY) WORK IF THERE ARE NO SOURCES IN THE NEW DESTINATION
// MEENS THAT YOU CAN'T RUN IT TWICE
// BUT YOU CAN DO CTRL / OPTION Z TO UNDO
app.doScript("main()", ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, "Make Inverse Hyperlinks");
function main()
{
var doc= app.activeDocument,
myHyperlinks =doc.hyperlinks.everyItem().getElements(),
l = myHyperlinks.length;
var hypSource, hypDestination, newDestinationName, hdps, hypDestinationPos, newDestination, newSource, newHL;
while (l--)
{
hypSource = myHyperlinks
.source.sourceText; hypDestination = myHyperlinks
.destination.destinationText; newDestinationName = hypSource.contents;
hdps = hypDestination.parentStory;
hypDestinationPos = Math.min(hdps.texts.itemByRange (0, hypDestination.insertionPoints[0].index).words.length - 1, 0);
newDestination = doc.hyperlinkTextDestinations.add(hypSource);
newDestination.name = newDestinationName + " ... " + newDestination.id + "_";
newSource = doc.hyperlinkTextSources.add(hypDestination.paragraphs[0].characters.itemByRange(0,-1));
newHL = doc.hyperlinks.add(newSource, newDestination, {});
newHL.name = newSource.sourceText.contents.slice(0, Math.min(20, newSource.sourceText.contents.length)) + " ... " + newHL.id + "_";
//newHL.source.sourceText.appliedCharacterStyle="2";
}
}
Trevor
Copy link to clipboard
Copied
Interesting script i'll study for sure but it assume hyperlinks and anchors already in the document.
Workin' on epub with endnotes i've previously created all anchors with the same name in both documents (text document and notes document).
From this scenario i've to create hyperlinks from text to note and back again.
Starting from insertionPoint, by me, solution could be to select anchor text and add hyperlink matching anchor's name.
Exporting epub there would be something like this in xhtml documents.
text.xhtml
<a id="n1c1" href="notes.xhtml#n1c1">1</a>
notes.xhtml
<a id="n1c1" href="text.xhtml#n1c1">1</a>
I hope not confusing you
best regards
Copy link to clipboard
Copied
Hi Foredit,
I didn't realize that you were working on an epub I would have to look into that and it would take me quite a bit of time.
As you are doing try use the imformation from your recent treads to figure it out and start more threads as required.
If you get desperate then I'm always happy to take a job for money ![]()
Regards
Trevor
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more