Hiding in Plain Sight: Solving InDesign Bugs with Scripting

TL;DR

Olav Martin Kvern used InDesign scripting to automate a workaround for an InDesign bug—demonstrating that scripting isn’t just useful for automation and creative effects; it can also be a powerful tool for overcoming InDesign bugs.

I’ve written a lot over the years, about the many uses of Adobe InDesign scripting: automating repetitive tasks; personalizing documents; customizing the application; achieving creative effects that would be difficult or impossible to do by hand; and other things.

But there’s something I do with scripting that I’ve never written about: using scripting to work around bugs in InDesign.

Bugs are an unavoidable fact of life for any piece of software, and a large, complex application like InDesign has its fair share (some might say more than its fair share).

There’s a reason for that. The number of engineers working on InDesign today is less than a tenth of what it was when I was working at Adobe. I’m often amazed that the team can respond to operating system updates, let alone add new features. It’s sadly inevitable that bugs will slip through the cracks.

While there are usually ways to work around InDesign bugs via the user interface, these approaches often require sacrificing design features. And they’re almost always tedious and time-consuming.

Here’s an example I ran into recently. My friend, the brilliant book designer and typographer John D. Berry, was working on the production for a book he’d designed. The design featured page footers that included the current page number, a symbol character, and some text.

John added the footer as a text frame on the parent page, as is typical for this sort of project, then added a page number marker to the frame, and finally typed in the other text.

John applied OpenType Oldstyle Numerals formatting to the page number marker, as is common in a lot of book design. The static text was formatted using All Small Caps.

As John laid out the book, everything looked good up to page 100. At that point, the last digit of the page number in the right-aligned footer (on the recto page) and the last character of the left-aligned static text (on the verso page) lost their formatting—they reverted to the document default text styling.

Verso (left-hand page) footer text frame

Recto (right-hand page) footer text frame

John sent me files so that I could try to diagnose the problem. I immediately focused on the page number marker. InDesign often has problems related to the variable text feature, and page numbering is a type of variable text.

Text variables are treated as single characters by InDesign’s composition system, which means that there are a number of bugs and limitations around the feature. Especially when the length of the variable extends to more than a few characters.

InDesign composes text as a series of “text runs”—which correspond to scripting’s “textStyleRanges”. InDesign keeps track of where these are by counting characters in the story. If its count is incorrect, formatting can change unexpectedly.

This is a well known bug that I’ve encountered before in slightly different forms.

I found that I could avoid the problem on the verso page by adding a space following the last character of the static text, but I couldn’t do that for the right-aligned page number on the recto page. It’s possible that one could add a fixed-width space following the number, and then move the text frame to the right to retain the text alignment, but that approach seems overly complicated.

It’s pretty clear that the bug is related to the length of the text—that the length of the page number special character is being calculated incorrectly. In fact, I found that if I started the section numbering at 1000, the problem moved two the last two characters, and kept on moving left for each added digit. InDesign somehow thinks that page numbers over 99 don’t exist.

The footers look fine…

 

…until you reach longer page numbers. Note incorrect formatting applied to the last character in each text frame.

 

Section starting with page 1000

 

Section starting with page 10000

 

Section starting with page 100000. This is starting to get silly.

 

I was having fun, so I kept adding zeros until InDesign objected. But you get the idea.

 

I realized that there were really two options—either change the formatting, or override the parent page text frames and enter the page number manually on every page. (I can think of a few more approaches, none of them good.**)

With InDesign scripting, the manual task that leaves the formatting intact becomes very easy. Once pagination is complete, all the script needs to do is override the footer from the parent spread on each page, then replace the page number marker character with the number of the page.

Here’s the code that does the work. The code overrides the parent page text frame, then replaces the automatic page number marker character with the page number (“page.name”).

 

I wrote another script that removes the overridden footer text frames and restores the document to its originals state. That way, John can return to his original layout, make any necessary pagination changes, and then run the script again.

The point is: InDesign scripting often gives us the tools we need to work around its bugs. Even bugs in scripting itself (say it ain’t so!) can often be compensated for by using other scripting approaches.

I can’t believe that I’ve never written about this use of InDesign scripting.

* The footers on a spread differ between the recto (right hand) and verso (left hand) pages, which means he couldn’t use section marker text for both pages, so he didn’t use that feature for either. Even if he had, the problem would remain.

** You could change the design—split the footer text frame into two text frames. If you do that, though, you lose the dynamic spacing between the static text and the page number.

 

Home » Hiding in Plain Sight: Solving InDesign Bugs with Scripting
100 Pine St., Suite 1250 | San Francisco, CA 94111 | 925-935-3899 | sales@siliconpublishing.com
© 2015- Silicon Publishing, Inc.
Privacy Policy