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
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)});
}
Copy link to clipboard
Copied
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.)