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

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

Explorer ,
Apr 15, 2024 Apr 15, 2024

Copy link to clipboard

Copied

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!

TOPICS
Scripting

Views

236

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
Community Expert ,
Apr 15, 2024 Apr 15, 2024

Copy link to clipboard

Copied

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();
}

 

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
Explorer ,
Apr 16, 2024 Apr 16, 2024

Copy link to clipboard

Copied

I'll give this a try - thank you!

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
Community Expert ,
Apr 15, 2024 Apr 15, 2024

Copy link to clipboard

Copied

@j25m27c 

 

What kind of editing do you need to do?

 

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
Explorer ,
Apr 16, 2024 Apr 16, 2024

Copy link to clipboard

Copied

LATEST

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!

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