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

How do i convert long urls to short text links to save space?

New Here ,
Aug 29, 2018 Aug 29, 2018

Copy link to clipboard

Copied

I've got a file that I'm working on and in that file there is a table with a one column that is all urls. These urls take up too much space so i wanted to change them to something short like "Click here for link" I know how to do it on a small scale with Edit Hyperlink option, but I've got about 300 links i need to do this to and i'm trying to save myself some work.

So essebtially what i want to do is change... https://www.thislinkiswaytolongandtakesuptomuchspace.com to something like Click here for link but i need to do that on a large scale.

Thanks

TOPICS
Scripting

Views

302

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
Advocate ,
Aug 29, 2018 Aug 29, 2018

Copy link to clipboard

Copied

You can try this script and modify according to your need,

var myDoc = app.documents[0];

//you can store your urls which are present in document using grep search or text search

var myLink = ["www.firstURL.com", "www.secondURL.com"];

// And store how link should show in text as per your need

var showText = ["click here for link", "click here for link"];

for(var i = 0; i < myLink.length; i++){

    app.findTextPreferences = NothingEnum.nothing;

    app.changeTextPreferences = NothingEnum.nothing;

    app.findTextPreferences.findWhat = myLink;

    app.changeTextPreferences.changeTo = showText

    myDoc.changeText();

    app.findTextPreferences = NothingEnum.nothing;

    app.changeTextPreferences = NothingEnum.nothing;

    app.findTextPreferences.findWhat = showText;

    var found = myDoc.findText();

    var counter = 0;

    var done = false;

    do{

        try{

            var myHyperlinkSource = app.activeDocument.hyperlinkTextSources.add(found[counter]);

            done = true;

            }

        catch(e){

            counter++;

            done = false;

            }

        }

    while(done==false)

    var myHyperlinkURLDestination = app.activeDocument.hyperlinkURLDestinations.add(""+myLink);

    var myHyperlink = app.activeDocument.hyperlinks.add(myHyperlinkSource, myHyperlinkURLDestination, {name: (found[counter].contents+"_"+counter)});

    }

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 ,
Aug 30, 2018 Aug 30, 2018

Copy link to clipboard

Copied

LATEST

According to the Object Model, the actual text that is the hyperlink "button" is pointed to by a HyperlinkTextSource property sourceText. So this is all it takes:

for (i=0; i<app.activeDocument.hyperlinkTextSources.length; i++)

{

app.activeDocument.hyperlinkTextSources.sourceText.contents = "Click for link";

}

And in case you don't have a character style applied, you'd better do that right away:

charstyle = app.activeDocument.characterStyles.item("link");

for (i=0; i<app.activeDocument.hyperlinkTextSources.length; i++)

{

app.activeDocument.hyperlinkTextSources.sourceText.contents = "Click for link";

app.activeDocument.hyperlinkTextSources.sourceText.appliedCharacterStyle = charstyle;

}

(Adjust the character style name "link" to your personal taste.)

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