Find and Replace text in Hyperlink URL?
Copy link to clipboard
Copied
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!
Copy link to clipboard
Copied
Based on your example a GREP search would do
w{3}\.\K.+?(?=/)
Copy link to clipboard
Copied
Can you provide very dumbed down instructions with pictures?
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
Ok here I am, I'm in the Find/Change menu in the GREP tab, I pasted the text into the Find What field then what? Where do I put the previous url base, where do I put the new one? What button do I press after that?
Copy link to clipboard
Copied
Great.
In the change to field you can insert the replacement text.
Then press find next. If it's a match for what you want you can select Change.
Copy link to clipboard
Copied
I just ran a test and it didn't work. All it did was highlight a part of one url that's in some body text, it's not looking at the hyperlinks.
Copy link to clipboard
Copied
Is it highlighting the portion of the url you want to change?
In the Replace field you need to insert the text you want it to change to.
At this point it seems like it would be beneficial for you to look up some video tutorials on how to do a find/change using InDesign.
Copy link to clipboard
Copied
No it is highlighting text in the document, I need to find and replace the base part of a hyperlink.
I'm here in the Adobe support community to get help lol. I already tried searching how to do this in videos and I'm totally lost.
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
Copy link to clipboard
Copied
… 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?
Copy link to clipboard
Copied
No, I couldn't get find and replace to to work for a hyperlinked url, just text in the document.
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
AHHH - penny finally drops! You also want the hyperlink itself to change... oh my!
Thanks for clarifying further, I didn't consider this possiblity.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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
😉
Copy link to clipboard
Copied
@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

