Skip to main content
Becca26946798d5iz
Participating Frequently
November 3, 2022
Question

Find and Replace text in Hyperlink URL?

  • November 3, 2022
  • 5 replies
  • 2357 views

Hi all,

 

I'm trying to figure out how to find and replace the base part of a URL hyperlink in an Indesign file with another domain.  So for example www.example.csod.com/12345 becomes www.somethingelse.csod.com/12345

 

I have an Indesign catalog with hundreds of hyperlinks that will be breaking in a couple months with a domain change and I want to make this transition as painless as possible.

 

Now I've seen this question answered with information about running a script, but I need someone to explain this to me as if I know nothing about scripts (because I don't haha).

 

Thank you in advance!

This topic has been closed for replies.

5 replies

pixxxelschubser
Community Expert
Community Expert
November 4, 2022

You can change the text of the hyperlink and the destination URL of the hyperlink something like this:

 

I tried the example in your first post and it works (initially just the first hyperlink in the document - written quick and dirty and not optimised).

var hyp = app.documents[0].hyperlinks[0];
if ( hyp.destination && hyp.destination.hasOwnProperty("destinationURL") && hyp.destination.destinationURL.length > 0 ) {
var destTxt = hyp.source.sourceText.contents;
var dest = hyp.destination.destinationURL;
var newDestTxt = destTxt.replace("example", "somethingelse");
var newDest = dest.replace("example", "somethingelse");

app.documents[0].hyperlinks[0].source.sourceText.contents = newDestTxt;
app.documents[0].hyperlinks[0].destination.destinationURL = newDest;
alert ("hyp[0] updated");
} else {
    alert ("no hyp[0] destination URL found");
    }

 

You just have to loop through all the hyperlinks and do error management. Maybe it can be simplified, but I don't usually write scripts for Indesign - there are a lot of people who can do it much better than I can.

 

If that works for you

Have fun

😉

Community Expert
November 5, 2022

@Becca26946798d5iz please try the script shared so graciously by @pixxxelschubser and let us know if this is what you need. If the idea is on the right track then we can work on extending the script if you need help in that aspect.

P.S.:- If you are new to using scripts and wonder how to use them, see the following article

https://creativepro.com/how-to-install-a-script-in-indesign-that-you-found-in-a-forum-or-blog-post/

-Manan

-Manan
pixxxelschubser
Community Expert
Community Expert
November 4, 2022

Ok, now I understand. You do not only want to change the text of one (several) existing hyperlinks but also the hyperlink targets of the hyperlink. This is not possible with search and replace. You need a script for that.

pixxxelschubser
Community Expert
Community Expert
November 4, 2022
quote

… I'm trying to figure out how to find and replace the base part of a URL hyperlink in an Indesign file with another domain.  So for example www.example.csod.com/12345 becomes www.somethingelse.csod.com/12345


By @Becca26946798d5iz

 

Sorry if I misunderstood you - but do you really need a grep for that? A simple text search
find:

.example.

replace:

.somethingelse.

should be quite sufficient? Or not?

Becca26946798d5iz
Participating Frequently
November 4, 2022

No, I couldn't get find and replace to to work for a hyperlinked url, just text in the document.

Participant
November 4, 2022

Here's a link to an InDesign article that I think is what you are looking to do in your document.

https://creativepro.com/batch-change-hyperlinks-across-a-whole-indesign-document/

Janine

Community Expert
November 4, 2022

Hi @Becca26946798d5iz,

Make a sample document for us to test it and then send the solution your way. Since you have little experience in excecuting find/replace queries it might be possible that some instruction is getting misinterepreted or missed and hence you are not seeing any results.

-Manan

-Manan
Becca26946798d5iz
Participating Frequently
November 4, 2022

Thanks Manan, here's a sample document for you.  

Community Expert
November 3, 2022

Based on your example a GREP search would do

 

w{3}\.\K.+?(?=/)

 

Becca26946798d5iz
Participating Frequently
November 3, 2022

Can you provide very dumbed down instructions with pictures?

Community Expert
November 3, 2022

Edit>Find Replace

Go to the GREP tab

 

Copy that text into the Find GREP field

https://helpx.adobe.com/ie/indesign/using/find-change.html