A typesetting treasure trove
At first glance, it may not look like much—but Peter Kahrel’s extensive online repository of free scripts is an essential resource for anyone who works on long documents in InDesign.
After hosting the script repository on his own website for many years, its future was in doubt late last year when Peter made the decision to relocate from the UK to Spain. His UK ISP refused to let him keep the site, or even set up redirection links.
Fortunately, David Blatner at CreativePro Network came to the rescue, and the repository now has a new home at CreativePro.com.
In this interview, Peter shares insights into the repository’s history, and some of the ways that InDesign typesetters can use his free scripts to make their lives easier.
Peter, how did you first get into scripting?
I worked as a typesetter, copy-editor, and indexer for more than thirty years. Much of typesetting and copy-editing is tedious, and to beat the tedium to some extent, I scripted as much as I could.
I had learned some Pascal programming when I was a student in the linguistics department at Amsterdam University. Then I learned Basic, and not long after, I got my hands on Turbo Pascal compiler, which I used a lot.
During my PhD program I got interested in AI (early days, in the 1980s) and learned Prolog. Then I drifted into typesetting, and learned how to script WordPerfect—first its own proprietary script language, but in later versions, WordPerfect’s script language was basically Turbo Pascal.
Apart from the three-month Pascal course (which was, in fact, not extremely useful because the two teachers rarely agreed with each other), I’m a self-taught script writer. The fact that I had studied formal linguistics helped, probably.
Why did you develop your online script repository?
The scripts reflect the work that I did, and most of them deal with text.
I thought that some people might be interested in some of my scripts, so I posted them online. When that appeared to go down well, I made a habit of posting scripts I did for myself that I thought would be generally useful. And I wrote up how to use them.
The repository doesn’t look very exciting; in fact, some years ago it was described by Gerald Singelmann as visually an Langeweile kaum zu übertreffen—‘unsurpassed boredom’. Though, he did say he liked the scripts!
All the pages are very simple, mostly text, lightly styled, and just some screenshots here and there when needed.
I do the pages in a text editor; I have no use for web editors. I did use Dreamweaver for a while, but thought it was nonsense to use a multi-megabyte (multi-gigabyte probably by now) application to produce text files a couple of kilobytes small.
So, I ditched Dreamweaver and have used a plain-text editor ever since.
An advantage is that because the pages are so simple, they load very quickly—and they’re easy to change.
Do you make changes to the repository often?
I usually fine-tune scripts when requested. When there’s a problem with a script I’ll try to fix it.
When someone is after some added or changed functionality, I’ll do it if it’s not too much work and if it intrigues me.
What do the scripts do?
In a way, the scripts reflect the features that InDesign lacks or lacked and which I needed. I have clusters of scripts in three areas where a lot of functionality is or was missing: footnotes/endnotes, indexes, and GREP.
Before CC2018, InDesign did just one type of note: footnotes. Thus, the Notes section includes scripts that convert footnotes to endnotes (and vice versa); convert footnotes to margin notes; enable inline footnotes; allow you to change the space between notes and text; better handling of table notes; column-spanning footnotes; footnotes in columns; and create hyperlinks (transferrable to EPUB) from note references to notes and return links.
Some of these scripts were made obsolete when Adobe implemented the respective feature in InDesign, but since there are still many old InDesign installations (CS6 is still used a lot), the scripts remain available.
This is probably the InDesign feature that benefits from scripting more than any other.
InDesign’s index is not very flexible and lacks some basic features, such as the possibility of creating more than one index in a document, using section numbers as locators (rather than just page numbers), no distinction between main text and notes, and several other glaring gaps.
When you have to rely on InDesign’s basic index feature for creating indexes, you’ll have a hard time. However, with scripting, InDesign’s index becomes a powerful tool.
With the Indexes and concordances scripts, it’s possible to use more than one index in a document; you can fix the poor sorting and implement different sort types (word-by-word and letter-by-letter). A much-requested feature, the possibility to create an index from a word list, is not difficult to script, and the repository contains some versions of such a concordancer.
Some other features are harder: section numbers as locators and indications of whether an index term is in a note or in the main text are hard to script, but it’s possible.
Other useful index features include various index statistics and audits. For example, most publishers are anxious that index entries are spread evenly across a book, which is almost impossible to judge by just looking at an index.
But there’s a script in the repository that shows the distribution of index references graphically, so that in a glance you see whether an index is lopsided or evenly spread.
A third text feature that benefits from scripting is GREP (Global Regular Expression Print), a sophisticated search and replace tool that enables you to manipulate text automatically.
InDesign’s GREP is very powerful as it is, but various things could be improved or added to.
For example, InDesign’s interface in the ‘Find/Change’ dialogue is a tiny entry field, which is fine for simple and short expressions. Construct more complex expressions, however, and soon you’ll wish you could write them on several lines.
The GREP Editor script creates a window in which you can write long expressions (making life a lot easier), and highlights everything that is matched by the expression (which is useful for debugging expressions).
But the GREP Editor doesn’t stop there. When GREP was first implemented (in InDesign CS3), the GREP wildcards and features that were exposed by the interface covered only part of what is available, and I exposed all GREP features in the GREP Editor’s interface.
Other scripts in the GREP section of the repository include:
- Chain GREP queries;
- Print an overview of all the GREP queries on the user’s computer;
- Display which GREP styles are used in a document; and
- Give a preview of the effects of a GREP query.
Are there other scripts available in the repository?
Yes, there are nearly 40 individual scripts in addition to the three clusters. Some are very complex and perform many functions, while others are relatively simple. Here are some of my favourites.
InDesign has no provision for defining custom kerning pairs (in contrast with QuarkXPress). Many years ago, there was an InDesign plug-in for custom kerning, but it was short-lived, never to be seen again.
The Kern script allows the user to define kerning pairs in a text file. A bonus of the script is that kerning pairs can look beyond a single font, which isn’t possible with traditional kerning approaches.
There’s a companion script that reads custom kerning pairs from a typeset document and creates a text file with kerning pairs which can be used later to kern other documents.
The only downside of the script—though it was never a problem for me—is that you have to run it every time the text changes.
There’s a script that exports book documents to individual PDFs, something that typesetters routinely do, and which InDesign still doesn’t do.
That script can also export documents page by page and/or section by section, optionally using section prefixes in the PDF file names. Some of this functionality is now present in InDesign.
Another script exports a book file and stores the book’s PDF name and location, the preset used, and some other characteristics. InDesign doesn’t do that, so every time you export the same book you have to enter this information again.
Yet another glaring omission in InDesign is the ability to sort anything. Indexes are sorted, naturally (though not always very well), and tables of contents can be sorted alphabetically. But there’s no provision to sort a word list, for example.
Here again, InDesign’s fabulous scriptability comes to the rescue.
The Language-aware paragraph sorter script sorts paragraphs, either language-specifically or neutrally. It also enables you to conduct retrograde sorting, or to sort numerically or on a particular character style.
And there’s a script to sort tables on up to three columns, either the whole table or a selection of rows.
What advice do you have for anyone who wants to get started with InDesign scripting?
Get as much practice as possible. You can do that by writing as many scripts as possible for yourself.
Get involved in some scripting forums, such as Adobe’s InDesign scripting forum, the InDesign Secrets scripting forum, and the German-language HilfDirSelbst forum. There are people there who can answer your questions and, after you’ve made a start, trying to solve other people’s problems is a good way to get familiar with InDesign’s object model.
My script repository has a section with links to books and other useful resources, which will help you learn the basics.
Most of all, you need determination: don’t be discouraged if you can’t get a script to work straight away. Try your best to get the script to work before you look for help.
About Peter Kahrel
Peter was born in Amsterdam, the Netherlands. He trained as a linguist at the University of Amsterdam and has an MA and a PhD, specialising in syntax, semantics, and typology.
After moving to the UK in 1994, he worked as a typesetter, editor, copy-editor, and indexer (and sometimes as a designer too) for publishers in the UK, the Netherlands, and Germany, preparing for the press both books and journals. He combined this with teaching at the Linguistics Department at Lancaster University.