Thanks for coming to InDesignSecrets.com, the world's #1 resource for all things InDesign!

Free Script to Automate Adding Visible URLs

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 http:// 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:

  1. Paste the URL at the insertion point
  2. Remove the prefix (http, https, etc) before and including the // at the start of the URL
  3. Check to see if there is a swatch called “Hyperlink” in the document. If not, it creates one.
  4. Check to see if there is a character style called “Hyperlink” in the document. If not, it creates one.
  5. Create a Hyperlink out of the URL
  6. Position the cursor at the end of the Hyperlink text
  7. 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!

Keith Gilbert

Keith Gilbert

Keith Gilbert is a digital publishing consultant and educator, Adobe Certified Instructor, Adobe Community Professional, conference speaker, lynda.com author, and contributing writer for various publications. His work has taken him throughout North America, Africa, Europe, and Asia. During his 30 years as a consultant, his clients have included Adobe, Apple, Target, the United Nations, Best Buy, General Mills, Lands' End, and Medtronic. Follow him on Twitter @gilbertconsult and at blog.gilbertconsulting.com.
Keith Gilbert

Latest posts by Keith Gilbert (see all)

  • - November 30, -0001
Related Articles
Comments

6 Comments on “Free Script to Automate Adding Visible URLs

  1. 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.

  2. 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.

  3. 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…

Leave a Reply

Your email address will not be published. Required fields are marked *