Skip to main content
Participating Frequently
April 15, 2024
Question

Script to view all URL hyperlinks at once and edit them in bulk

  • April 15, 2024
  • 2 replies
  • 764 views

Hi there,

 

I've searched through the forums and have not been able to find or put together a script that suits my needs. I have an Indesign document with hundreds of URL hyperlinks linked to invisible rectangles, and I want to be able to view all the URLs in a list (all at once, or from a specified page range) in a window and edit them there instead of having to go to each page to Edit Hyperlink. All the URLs are unique so mass Find/Replace scripts are not useful to me.

 

Is a script possible for my needs, or is there an alternative option such as using IDML? I'm on a Mac if that makes any difference!

 

Thanks in advance!

This topic has been closed for replies.

2 replies

Robert at ID-Tasker
Legend
April 15, 2024

@j25m27c 

 

What kind of editing do you need to do?

 

j25m27cAuthor
Participating Frequently
April 16, 2024

I need to edit the URL of each hyperlink. They're all unique hyperlinks so I cannot use a simple Find/Replace script. Hence why I was hoping I could pull all the URLs up in a certain window and edit them there without having to go to each box to right-click and edit the hyperlink 🙂 Thanks!

brian_p_dts
Community Expert
Community Expert
April 15, 2024

I'd probably approach it as two separate scripts. The first main would get you a txt file to your desktop of all the URLs. The second would read and replace from that file. Could also get the hyperlinked item's page and sort that way once the txt is generated: 

var main = function() {
    var f = File(Folder.desktop + "/hyperlink_log.txt");
    f.encoding = "UTF-8";
    f.open("w");
    var d = app.activeDocument;
    var hls = d.hyperlinks;
    var i = hls.length;
    while(i--) {
        try {
            f.writeln(hls[i].name + "\t" + hls[i].hyperlinkURLDestination.destinationURL);
        } catch(e) { /*not a url*/ }
    }
    f.close();
}


var main2 = function() {
    var f = File(Folder.dektop + "/hyperlink_log.txt");
    var d = app.activeDocument;
    f.encoding = "UTF-8";
    f.open("r");
    var l;
    while(!f.eof) {
        try {
            l = f.readln().split("\t");
            d.hyperlinks.itemByName(l[0]).hyperlinkURLDestination.destinationURL = l[1];
        } catch(e) {}
    }
    f.close();
}

 

j25m27cAuthor
Participating Frequently
April 16, 2024

I'll give this a try - thank you!