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

Create Hyperlink Text Variable

Participant ,
Mar 24, 2023 Mar 24, 2023

Copy link to clipboard

Copied

Is there a way to create a text variable that contains a hyperlink?

 

I am working on automating a directory where items link the company URL, and service phone number occur multiple times throughout the publication. This makes them perfect for text variables so I can update them from one place when they change. However, I also need these items to be hyperlinks connected to specific URLs as well (i.e. to the webiste and "tel:#"). Is there a good way to accomplish this?

TOPICS
How to , Scripting , Type

Views

546

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 1 Correct answer

Participant , Mar 27, 2023 Mar 27, 2023

Thanks for the feedback!

I am working on a fully automated publishiung workflow with documents where the service department phone number occurs numerous times through the document. Enough times that setting them up as a text variable makes sense. However, I also want to be able to ensure these phone numbers are setup as "tel:" links when exported to PDF. Additionally, since I am trying to create a fully automated workflow, manually applying the hyperlink is a off the table.

 

The scripting solution

...

Votes

Translate

Translate
Community Expert ,
Mar 25, 2023 Mar 25, 2023

Copy link to clipboard

Copied

Not sure with text variables - as they are considered to be 1 character in InDesign.

When exported to PDF for example it is converted to text. 

So as a Text Variable www.adobe.com would probably work for the PDF as most PDF readers would convert the URL to a link automatically.

And you could technically have as a Text Variable "Visit the Website" - and have the Website as a URL hyperlink for the text. But you'd have to apply that to all the instances of the Variable.

 

Bur for Tel no. - a bit more difficult maybe.

 

Thinking about it as I don't have access to InDesign here ----hmmmm----- 

There's quite a few scenarios that spring to mind that might work and instances where it wouldn't work depending on the content.

 

Can you share a bit more abou the workflow - and how you want it to be implemented?

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
Enthusiast ,
Mar 25, 2023 Mar 25, 2023

Copy link to clipboard

Copied

I tested a bit with hyperlinks and text variables, and it looks like hyperlinks are only compatible with text in scripting.

It will not accept the below:

app.activeDocument.textVariables.item('VAR_NAME').associatedInstances[0].resultText


Something like this will work with modification:

aD = app.activeDocument;
var source = aD.hyperlinkTextSources.add(aD.selection[0].words[0]);
var dest = aD.hyperlinkURLDestinations.add("www.adobe.com");
aD.hyperlinks.add(source,dest);


I don't think text variables are a good option primarily because the text always stays the same. If that's the case you could just use parent pages but then you're locked into layout.

This may be obvious, but when you set a hyperlink it actually creates a character style and color. So instead you could indicate links by styles and use a script to update them, or perhaps tags.

Or... What about just using the hyperlinks panel? Once the links are in there you can batch edit, and it gives you visibility to things not matching.

iamwickedtall_0-1679806388212.png

 

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 ,
Mar 27, 2023 Mar 27, 2023

Copy link to clipboard

Copied

Thanks for the feedback!

I am working on a fully automated publishiung workflow with documents where the service department phone number occurs numerous times through the document. Enough times that setting them up as a text variable makes sense. However, I also want to be able to ensure these phone numbers are setup as "tel:" links when exported to PDF. Additionally, since I am trying to create a fully automated workflow, manually applying the hyperlink is a off the table.

 

The scripting solution iamwickedtall suggested feels like it is on the right track, though the limitation on attaching links to variables is frustrating.

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
Enthusiast ,
Mar 27, 2023 Mar 27, 2023

Copy link to clipboard

Copied

LATEST

If it's fully automated, phone numbers and websites are easy enough to find and replace with a grep statement, but what I'm assuming may happen in your document is text like "call us" or "visit our website".

I did find that the hyperlinks function will accept a selection, but I could not figure out how to select a variable instance directly based on object model.  That said, I was able to loop through text variables via GREP, select the variable and assign a hyperlink that way. The next steps would be to create/assign a character style and edit/remove an existing hyperlink:

 

//Set findChangeGrepOptions before this
aD = app.activeDocument;
app.findGrepPreferences.findWhat = "~v";
haystack = app.activeDocument.findGrep();
//Create Destination outside of the loop so that anything created is associated with eachother in the hyperlinks panel
var dest = aD.hyperlinkURLDestinations.add("tel:999.999.9999", { name: "Phone Number" });
for (i = 0; i < haystack.length; i++) {
    needle = haystack[i];
    app.select(needle);
    if (needle.textVariableInstances[0].resultText == "POTATOHEAD") {
        var source = aD.hyperlinkTextSources.add(aD.selection[0]);
        //Create a name for the Hyperlink, it must be unique so it's incremented below
        var needleName = needle.textVariableInstances[0].resultText + " " + i;
        aD.hyperlinks.add(source, dest, { name: needleName });
    }
}

 

 

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