Assigning Hyperlinks Automatically to SKUs and other Text with a Script
Have you ever had to make 1,000 hyperlinks in a document? Tedious! For example, here’s some text from a catalog, and you can see there’s a productname and a SKU (ID number):
We want to add a hyperlink to each one of those numbers, so that it links to a URL on a website. And, here’s the key: the URL on the website includes the product ID. For example the number 1234 would link to www.mysite.com/product/1234 (or something like that).
If you had to do this, you’d wish you were working by the hour, right? Because this is going to takea long time and be really boring. But what if there were a way to do it superquickly? What if I had a script to do it for me?
That was the question that came up at The InDesign Conference last year, and master automator Kris Coppieters answered by writing a script. He’s giving away this powerful script for free (details below). The script is called Gryperlink:
That weird name is a combination of hyperlink and the word GREP, and you’ll see why in just a minute.
Here’s what my document looks like after running the script (by double-clicking it):
Look at all the hyperlinks! And each hyperlink is exactly in the format I wanted:
So this is amazing. Now, if you want to do this trick with your documents, you’ll need a couple things. You need to download the script, which you can find here. This page at Rorohiko.com actually shows you how to download and install it. But then here’s the part that is a little tricky: you need to customize the script so that it works with your web site and your product ID numbers.
You need to open the script in a text editor—you want to be careful not to open this in Word or an app that can apply formatting because that will mess it up. Then scroll down a little and you’ll see a section called Configuration:
The “link” section is easy: just change that to your site with the proper file path. The $1 is going to be the product number, so leave that part alone.
The “charStyleName” is also straightforward: this needs to be the name of a character style in your document (which you have to have built already).
But the search pattern is harder: in order for this to work, you have to understand GREP, which is a way to find patterns in text using special codes. There are a number of great resources for GREP and InDesign here on our site.
In the example above, that “backslash-d” means a digit (a number), and the plus and question mark means “one or more”. So this means look for one or more digits followed by a dash, followed by one or more digits, and another dash, and then some more digits. I know it looks scary at first, but once you get the hang of it, it’s pretty straightforward. Of course, you need to customize the script search for ID numbers that match your sku style. Once you have all that, you save it, come back to InDesign, and run the script.
GREP is powerful stuff… Scripting is powerful stuff… Put ‘em together and you can save yourself a huge amount of time!
Many thanks to Kris Coppieters at Rorohiko for that script. If you ever need someone to create a custom, large-scale publishing automation workflowfor your company, talk to Kris.