• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers

InDesign Javascript hyperlinks question

Participant ,
Oct 24, 2022 Oct 24, 2022

Copy link to clipboard

Copied

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.

TOPICS
Scripting

Views

70

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 2 Correct answers

Community Expert , Oct 24, 2022 Oct 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

Likes

Translate

Translate
Community Expert , Oct 24, 2022 Oct 24, 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
...

Likes

Translate

Translate
Community Expert ,
Oct 24, 2022 Oct 24, 2022

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Oct 24, 2022 Oct 24, 2022

Copy link to clipboard

Copied

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.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 24, 2022 Oct 24, 2022

Copy link to clipboard

Copied

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];
    }
}

 

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Oct 25, 2022 Oct 25, 2022

Copy link to clipboard

Copied

LATEST

Hi there,

Thanks for the help and the code examples.

I should re-read Manan's post again, I'd not looked at the methods available I was too focussed on the properties.

Thank you once again, much appreciated 🙂

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines