Free Script to Automate Adding Visible URLs
With this script you can copy any URL and instantly insert it as a live hyperlink your InDesign documents.

I do a lot of writing for InDesign Magazine, Adobe, and other print and PDF publications. I do most of my writing right in InDesign. The editorial style of print and PDF publications usually dictates that all hyperlinks be displayed as visible URLs, often using a URL shortener like Bitly.
I got really tired of visiting a web site, generating a shortened URL, copying the URL, pasting it into InDesign, removing the https:// from the front of the URL, selecting the remaining URL, creating a URL hyperlink with the correct settings, and moving the cursor to the end so I could continue typing.
After repeating this process several hundred times over the last few months, a thought slowly wormed its way into my thick skull: “hey, I should write a script to do this!” You’d think this would have occurred to me earlier. After all, I’ve written a title called InDesign Scripting Made Easy for Lynda.com, and have written countless custom scripts for clients.
I finally got around to hammering out the script, and you can download it here. To learn how to install a script, watch this video. Then, display your scripts panel on the screen (Window > Utilities > Scripts). Then, to use the script, visit a website, and copy the URL to your clipboard. Then, choose an insertion point and double-click on the script in the Scripts panel. The script will:
- Paste the URL at the insertion point
- Remove the prefix (http, https, etc) before and including the // at the start of the URL
- Check to see if there is a swatch called “Hyperlink” in the document. If not, it creates one.
- Check to see if there is a character style called “Hyperlink” in the document. If not, it creates one.
- Create a Hyperlink out of the URL
- Position the cursor at the end of the Hyperlink text
- Set the character style to “none” so you can continue to type after the hyperlink text.
I hope that you find this useful. I sure saves me time and aggravation each day!
This article was last modified on July 25, 2019
This article was first published on February 3, 2016
Hello. Thanks for this super useful script. I use it all the time. However, I do run into issues now and again. I actually posted about this previously thinking the script had stopped working on a new version on INDD, but it turns out the error I get is document based. It works on some documents, and not on others. This is the error I get when it doesn’t work:
JavaScript Error!
Error Number: 55
Error String: Object does not support the property or method
‘sourceText’
Engine: main
File: /Users/eugenio/Library/Preferences/Adobe InDesign/Version
20.0/en_US/Scripts/Scripts Panel/Add hyperlink to selected text from clipboard.jsx
Line: 31
Source:
app.doScript(Main, undefined, undefined,
UndoModes.ENTIRE_SCRIPT, “Run Script”);
I can have 2 documents open and copy a URL, and the script will work in one file, but not the other. I’ve tried saving IDML versions of the files where it doesn’t work, but that doesn’t fix the issue.
Posting to see if anyone has any idea why it wouldn’t work on some documents, but work fine on others.
Thanks.
Hi Eugenio. If you can send me a file where the script fails, I’d be happy to take a look. I would need the ID file as well as exactly where in the file you are trying to create a hyperlink with the script. You can upload files here if you’d like: https://www.dropbox.com/request/DAEhtPiu0Vc2RCg5OLLC
Thanks so much for this script Keith. I’ve been using it for about a year. It recently stopped working though, guessing because of an INDD update. I’m using INDD 18.2.1 on Mac OS 13.2.1 and receive the following error when I try to use it:
JavaScript Error!
Error Number: 55
Error String: Object does not support the property or method
‘sourceText’
Engine: main
File: /Users / eugenio/Library/Preferences /Adobe InDesign /Version
18.0/en_US/Scripts/Scripts Panel/Add hyperlink to selected text from clipboard.jsx
Line: 31
Source:
app.doScript(Main, undefined, undefined,
UndoModes.ENTIRE SCRIPT. “Run Script”;
If you have time, could you please look into it. Much appreciated.
Hi Eugenio- I just tried the script in InDesign 2023 and it works as expected. First, be sure you have copied a full URL to your clipboard, then put your cursor in a text frame and run the script.
Hi Keith,
I found this awesome script that turns this:
Linkedin Profile: https://secure.yourirvine.org/CA/city-of-irvine/catalog?filter=c2VhcmNoPTE0MjA5
into this:
Linkedin Profile (but as a hyperlink from the link that follows it.
The script below is what I found…
——————————–
var doc = app.activeDocument;
// get URL
app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.nothing;
app.findGrepPreferences.findWhat = ‘(?i)(?’;
var mURL = doc.findGrep();
// get Texte
app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.nothing;
app.findGrepPreferences.findWhat = ‘LinkedIn Profile:’;
var mSource = doc.findGrep();
for (var k = 0; k <mSource.length; k++){
var mHyperlinkDestination = doc.hyperlinkURLDestinations.add(mURL[k].contents);
var mHyperlinkTextSource = doc.hyperlinkTextSources.add(mSource[k]);
mHyperlink = doc.hyperlinks.add(mHyperlinkTextSource,mHyperlinkDestination);
mHyperlink.name =mURL[k].contents;
mHyperlink.visible=false;
}
//remove URL text
app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.nothing;
app.findGrepPreferences.findWhat = '(?i)(?’;
app.changeGrepPreferences.changeTo = ”;
doc.changeGrep();
//rename ‘LinkedIn Profile: ‘ to ‘LinkedIn Profile’
app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.nothing;
app.findGrepPreferences.findWhat = ‘LinkedIn Profile: ‘;
app.changeGrepPreferences.changeTo = ‘LinkedIn Profile’;
doc.changeGrep();
——————————–
What I need is for it to do the same thing to this:
#14209 https://secure.yourirvine.org/CA/city-of-irvine/catalog?filter=c2VhcmNoPTE0MjA5
to this:
#14209 (but with the hyperlink applied as it did to the first one.
Please help, I am super close to being the hero and completing this script for my team.
What can I do?
Hi Keith,
I have watched your tutorial “InDesign Scripting Made Easy”on Lynda.com. It was me who requested Lynda for an Article on Indesign scripting, couple of months ago. I appreciate your effort in creating such a nice Tutorial. I can say it is a good start for beginners like me. However, I feel like that it contains the basics only. Just taking the liberty to ask if you can put more Tutorials on Lynda.com, moving from Beginner to Advance and Master levels.
For example:
Exporting a PDF/IDML/Package/JPG etc with options on particular locations.
Renaming the folder/file after performing some task.
Getting user input and performing actions.
Getting the location of the file, creating folders and sub-folders at that location etc etc.
Hope you can help us to learn scripting…
Hi Keith,
thanks for this.
Nonetheless I’d like to share a more automated (but less feature-rich) solution which is based on GREP and Character Styles (and a small “hack” if I can call it this).
The proof-of-concept can be downloaded from this link:
https://drive.google.com/file/d/0B_pLmZ05_3rcQW9pQWd2ZE5pc1U/view?usp=sharing
It works the following way:
– GREP checks if the text contains any substrings containing “http”. If yes, applies URL Character Style (blue).
– At the same time it “removes” the http-part from the beginning (see URL Character Style how it goes).
– One has to make sure having hyperlinks included upon PDF export, since this procedure does not create hyperlinks (but InDesign can of course create them when exporting to PDF).
Hi Adam. Thanks for sharing this. Very clever use of GREP styles. It works great. One small thing…
Keep in mind that checking the Include: Hyperlinks option when you export a print PDF from InDesign doesn’t actually convert hyperlink text to live hyperlinks in the PDF. This option only includes hyperlinks that are created as hyperlinks in InDesign. It may appear to be converting hyperlink text to live hyperlinks, because Acrobat itself recognizes text that “looks” like hyperlinks and creates a hyperlink on-the-fly, but ONLY if you have the “Create Links from URLs” option selected in Acrobat’s Preferences > General.
So, to guarantee that hyperlinks will always work for everyone in all Acrobat readers, you should create actual hyperlinks in InDesign’s Hyperlinks panel, or by choosing “Type > Hyperlinks & Cross-References > Convert URLs to Hyperlinks” in InDesign.
Oh, yeah, thanks, for mentioning, you are right. :)
I am still missing a GREP-based replacement feature from the app (without the used hack). So to be clear: I need something like the GREP styles, but instead of applying a style, it’d replace a string with another one dynamically.
Hi Keith,
thank you for sharing this.
I tested the script and there was an error on line 78.
You are using an English string for the “[None]” character style there.
I’m using a German version, that couldn’t understand that string.
I think, it’s better to address that character style by its index number.
That should run in all versions of InDesign all over the world:
myLastIP.appliedCharacterStyle = myDoc.characterStyles[0];
Uwe
Thanks for the helpful suggestion, Uwe. I apologize for forgetting about all users of non-English versions of InDesign! I’ve made the change you suggested to the script, and updated the script on the Web site.