Skip to main content
Participant
December 12, 2024
Question

Batch Edit Hyperlinks

  • December 12, 2024
  • 2 replies
  • 509 views

Hi All,

I am looking for a way to batch rename hyperlinks in my In Design files.  Currently I have Hyperlinks linking every product in a printed catalog to the the product page on the web. However we have websites in 3 countries, so I want to be able to change all the .coms to  .au and then again to .ca.  Previously we have been achieving this by exporting the idml file and then find and replace in the design map text file.  However, when I reopen the idml files this year the same way I did last year they are completely blank in Indesign.

This topic has been closed for replies.

2 replies

Peter Kahrel
Community Expert
Community Expert
December 13, 2024

This is fairly easy to script in InDesign itself, no need for the IDML-roundtrip (this version changes .com to .au):

// Change .com to .au
var h = app.activeDocument.hyperlinks.everyItem().getElements();
for (var i = h.length-1; i >= 0; i--) {
  currentURL = h[i].destination.destinationURL;
  if (h[i].destination instanceof HyperlinkURLDestination
      && /\.com$/.test (currentURL)) {
    h[i].destination.destinationURL = currentURL.replace(/(.+\.)(.+)$/,'$1au');
  }
}

 This version changes .com to .au.

 

It changes just the destination URL. If the source text and/or the link's name in the Hyperlinks panel are also the link name you need some additional code.

sns73081Author
Participant
December 18, 2024

Thank you!  We have beeen looking for a better way! 

leo.r
Community Expert
Community Expert
December 12, 2024

Maybe something has changed in your IDML editing process (different text editor etc.)

 

As a test, try to open the appropriate design map file and manually change just one link, then open IDML in InDesign. Will it work? 

sns73081Author
Participant
December 12, 2024

I canged just one and it opened correctly in InDesign.  I checked the one that I canged to see it the change to the hyperlink carried over and it did.

 

leo.r
Community Expert
Community Expert
December 12, 2024

Then it looks like something is going amiss during your batch-replace process. Maybe the text editor inserts some invisible characters or something else. Try a different text editor; make sure it only produces plain text and not RTF or something like this.