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

Update Text (Names) with Email Addresses (Hyperlinked)

New Here ,
Apr 09, 2019 Apr 09, 2019

Copy link to clipboard

Copied

In the normal InDesign process to create an email hyperlink I do the following:

Copy the email address to be created.

Select the individual's name for the link.

Right-click and select New Hyperlink.

Paste the email address.

This results in a link that shows a person's name, but has the hyperlink in hidden code.

So, clicking on the entry Doe, John would create a new email in the default email application but would not look like an email address.

I'd like to script this, to either copy the email address from the same ID document or from an external list, similarly to a list merge. I have effectively zero experience in scripting.

Has anyone seen such a script or knows a source they can point me toward?

Thanks!

Rich

TOPICS
Scripting

Views

623

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 ,
Apr 09, 2019 Apr 09, 2019

Copy link to clipboard

Copied

Hi Rich:

We have an InDesign Scripting forum for these sorts of questions. I'll move this over there for you so that you can can an answer to your scripting question.

~Barb

Votes

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 ,
Apr 09, 2019 Apr 09, 2019

Copy link to clipboard

Copied

Hi Rich,

We would need some mechanism to identify which text is to be hyperlinked, taking que from another question posted on the forum i am taking that identifier to be any text in the document that is between [], after the script is done the brackets would be removed and only the text within it is hyperlinked. The other requirement is how do we feed in the email addresses, we can use a text file with email addresses on a single line, some sample entries for this file could be as follows

mailTo:First@g.com

mailTo:Second@g.com

Once you have added brackets in your document to identify the text to be hyperlinked and created the text file, then run the following code

app.doScript(createHyperLink, ScriptLanguage.javascript, undefined, UndoModes.ENTIRE_SCRIPT, "Email Hyperlink");

function createHyperLink()

{

    var fi = new File("/Users/manan/Desktop/abc.txt")    //Change to the path of your input file

    if(!fi.exists)

    {

          alert("Input file does not exist")

          exit()

    }

    fi.open("r");

    var data = fi.read().split('\n')

    app.findGrepPreferences.findWhat = "\\[.*?\\]"

    var res = app.documents[0].findGrep(true)

    data = data.slice(0, res.length)

    while(a = res.shift())

    {

        a.contents = a.contents.substring(1, a.contents.length - 1)

        var source = app.documents[0].hyperlinkTextSources.add(a)

        var dest = app.documents[0].hyperlinkURLDestinations.add(data.pop())

          app.documents[0].hyperlinks.add(source,dest, {name:a.contents})

    }

    app.findGrepPreferences = NothingEnum.nothing;

}

P.S. :- This code would work on the whole document, if you need to modify it to work on selected textframe it known i will modify the code to that effect.

-Manan

Votes

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 ,
May 01, 2019 May 01, 2019

Copy link to clipboard

Copied

LATEST

Hi Rich

My Hyperlinker script may be able to help you, depending on the nature of your document. It has a 'custom search' feature that allows you to do a GREP powered find, then optionally add the result to a destination URL. It could be achieved in two different ways, neither of which require any kind of external list:

  1. If a person's name is repeated many times, and you want every instance of their name to link to the same email address, that's super easy—you would just enter their name in the 'Source regex' field, and enter their email address in the 'Destination URL' field. But that would still take a lot of time if there are dozens of different names.
  2. If you have lots of different names, my script could be made to work if each of the people's names relates to their email address in a consistent way. For example, if 'Doe, John' links to John.Doe@example.com, and 'Doe, Jane' links to Jane.Doe@example.com, etc, it could be done. This solution would take a bit more time to explain though, and the question is a few weeks old now… but let me know if you'd like me to expand on this answer.

Cheers

Kal

Votes

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