Skip to main content
deckarduk
Inspiring
October 24, 2022
Answered

InDesign Javascript hyperlinks question

  • October 24, 2022
  • 1 reply
  • 739 views

Hi there,

Using the following (trimmed down)...

app.findGrepPreferences.findWhat = "FredBloggs";
var myFound = app.activeDocument.findGrep();

 ... I'm able to find an instance of the word I'm looking for.

The text in question has a Hyperlink Text Anchor on it in the InDesign document.

I've listed all the properties of myFound[0] but can't see anything to do with hyperlinks/anchors etc. Have I missed something or isn't that property available?

Please can someone point me in the right direction.

Thanks in advance.

This topic has been closed for replies.
Correct answer brian_p_dts

Hyperlinks are not accessible via GREP, I don't believe. Building off your script, you can use @Manan Joshi's solution: 

 

app.findGrepPreferences.findWhat = "FredBloggs";
var myFound = app.activeDocument.findGrep();
var myHypes, nh, hypeTextSource, anch;
var i = myFound.length;
while(i--) {
    myHypes = myFound[i].findHyperlinks();
    nh = myHypes.length;
    while(nh--) {
        hypeTextSource = myHypes[nh].sourceText;
        anch = hypeTextSource.insertionPoints[0];
        //do something with the ip
    }
}

Faster probably would be to just find the doc's textsources and, if the contents match your find, do something: 

var hlts = app.activeDocument.hyperlinkTextSources;
var i = hlts.length;
while(i--) {
    if (hlts[i].contents == "FranksBlogg") { 
        //do something with hlts[i].insertionPoints[0];
    }
}

 

 

1 reply

Community Expert
October 24, 2022

You can look at the findHyperlinks method on the text, this will give you a list of all the hyperlinks in the text. One interesting discussion on this topic can be accessed from the link below

https://community.adobe.com/t5/indesign-discussions/finding-hyperlinks/m-p/1767663#M268273

-Manan

-Manan
deckarduk
deckardukAuthor
Inspiring
October 24, 2022

Thanks for the help Manan, I'll look into findHyperlinks.

Is it possible to access a 'Hyperlink Text Anchor' property for each instance of the findGrep() method above?

Thanks again.

brian_p_dts
Community Expert
brian_p_dtsCommunity ExpertCorrect answer
Community Expert
October 25, 2022

Hyperlinks are not accessible via GREP, I don't believe. Building off your script, you can use @Manan Joshi's solution: 

 

app.findGrepPreferences.findWhat = "FredBloggs";
var myFound = app.activeDocument.findGrep();
var myHypes, nh, hypeTextSource, anch;
var i = myFound.length;
while(i--) {
    myHypes = myFound[i].findHyperlinks();
    nh = myHypes.length;
    while(nh--) {
        hypeTextSource = myHypes[nh].sourceText;
        anch = hypeTextSource.insertionPoints[0];
        //do something with the ip
    }
}

Faster probably would be to just find the doc's textsources and, if the contents match your find, do something: 

var hlts = app.activeDocument.hyperlinkTextSources;
var i = hlts.length;
while(i--) {
    if (hlts[i].contents == "FranksBlogg") { 
        //do something with hlts[i].insertionPoints[0];
    }
}