Indiscripts

Tips

Scripters corner: howtos, tips and tricks (InDesign ExtendScript).

SelToPng | Quick InDesign-to-PNG Serializer

As an InDesign maniac I often use it for achieving tasks that would normally involve Illustrator or Photoshop. The best example of this deviance is PNG conversion. You read it well! And here is a tool that translates any InDesign shape, group, or whatever, into a PNG stream. Not a big deal, but let me explain…

Continue reading...

Coordinate Spaces & Transformations in InDesign — Chap.4 (Draft)

Chapter 4 of our “Spaces & Transform” eBook is probably both the trickiest and the most important. It tries to reveal the intricacies behind the Scripting DOM resolve() method, the unique tool for setting and processing InDesign locations with respect to the underlying coordinate systems. I spent months figuring out its obscure syntax and improving my knowledge on that particular topic. Understanding the location resolver is a crucial step for developing scripts that can deal in depth with geometry and transformations in InDesign.

Download chapter 4 (PDF, 12 pages -- DRAFT)

Continue reading...

Why I Do Not Use Meaningful Variable Names (Anymore)

Without doubt this is a “very bad practice.” When it comes to naming arguments and variables, every programmer should prefer descriptive and intention-revealing names over short forms. We all read this rule in Clean Coding bibles. Tokens like userName, swatchArray, or currentWordCount sound of course much better than s, a, and i

Continue reading...

On Dichotomic Divide-and-Conquer Algorithms

From what I observed, InDesign scripters do not naturally resort to the dichotomic (or binary) search algorithm when it comes to find a numeric solution to problems as wide as adjusting frame bounds to some constraint, determining an optimal text size, or simply accessing a needle in the haystack. Yet the binary search approach is nearly always the best. So let's make it more popular…

Continue reading...

Coordinate Spaces & Transformations in InDesign — Chap.1-3

Dealing with coordinate spaces and transformation matrices is one of the most obscure and underappreciated exercises in InDesign scripting and programming. The fault mainly lies with Adobe documentation, especially the Scripting DOM reference, which does not clearly explain the topic and some of its essential keys. The following document (PDF, Chapters 1-3) attempts to shed some light on the beast…

Download chapters 1, 2, and 3 (PDF, 22 pages)


• Next chapter now available: “Coordinate Spaces & Transformations in InDesign — Chapter 4”

Reconsidering Array.sort( ) in ExtendScript/JavaScript — Part 2

In my previous post I introduced some key concepts and tools for benchmarking Array.sort() and took you through the “standard model” of optimizing the callback function. We also emphasized that, of course, it is impossible to go faster than the native method. If these clues made you sit up and take notice, it's time to go one step further…

Continue reading...

Reconsidering Array.sort( ) in ExtendScript/JavaScript — Part 1

The pattern array.sort(compareFunc) is widely used by JavaScript programmers when elements being sorted are not supposed to represent basic strings in the sense of UTF16 ordered character sequences. In particular, sorting numbers forces you to provide that stupid custom compareNumbers routine which, in most cases, just looks like function(x,y){return x-y}. And even when you have to sort actual strings, there are countless situations where the default Unicode code point order is inappropriate. But a question arises: what is the performance cost of using a non-native comparison routine?

Continue reading...

Drawing Sine Waves in InDesign

Bézier curve approximation of sine waves

Computing Bézier curves that really look like sine waves is an exciting challenge for script developers. One needs to deal with both optimizing control points, transforming coordinate spaces and splitting curves. Here is a function that solves it all in ExtendScript for InDesign.

Continue reading...

How to Operate IndexMatic & BookBarcode in InDesign CC

For the time being, neither IndexMatic nor BookBarcode is supposed to properly work in InDesign CC. New releases are being implemented, but this takes much more time than expected. Anyway a few weeks ago Eddy Van Hoeke from Scriptopedia found an amazing trick that makes both iX² and bB virtually compatible with the latest InDesign versions. And it boils down to one instruction…

Continue reading...

ExtendScript Core Entities Diagram

Exploring the prototypal relationships between basic ExtendScript's entities reveals an interesting network of hidden objects. The following diagram shows that ExtendScript's own implementation of JavaScript is deeply connected with a root function (referred to as [[Function]] in the figure) which provides the actual prototype—that is, the __proto__ property—of many visible objects, including Function and Object themselves…

Continue reading...

Page Range Formatter

Given an unordered set of page numbers—e.g. {13, 9, 25, 12, 11, 8}—we often have to compute and output a range specification in the form "8-9; 11-13; 25". While this topic has been already discussed in the InDesign scripting forum, I'd like to explore today a slightly different approach…

Continue reading...

‘Sprite’ Buttons in ScriptUI [UPDATE]

A sprite usually refers to a primary image which is integrated in a larger scene. The term was popularized by Dave Shea in his 2004 article “CSS Sprites: Image Slicing’s Kiss of Death” which describes how to render the multiple states of a button or icon from a single composite image. I discovered that we can derive this technique to create attractive buttons in ScriptUI 4.0 and later…

Continue reading...

Making String.split() support U+0000 in ExtendScript CS4

For obscure reasons ExtendScript 3.x is somewhat allergic to the character "\x00" (U+0000). Some String and RegExp routines become silently defective as soon as your source string contains one or more NUL character. Although most of these bugs have been fixed in CS5 (ExtendScript 4.1), this still leads to compatibility and portability issues. Here is a snippet that allows to split any string and get proper results in all versions.

Continue reading...

How to Augment and Process Nested Groups (CS4-CS6)

Dealing with groups is a major headache for InDesign scripters. On one hand, the Group object has no injection method to offer, which makes difficult to append existing page items into a given group. On the other hand, although the Groups API exposes a promising add() method, nobody has ever managed to use this feature from any PageItem.groups area, so we seem doomed to perpetually rebuild groups from scratch.

Continue reading...

The Shortest-Ever Aphorism Generator

As an InDesign scripter, you probably know that PageItems, Paragraphs—or any other collection—exposes a method named anyItem() which randomly digs up a sample in the set. The only question is: what the hell can it be used for?

Continue reading...

ScriptUI Fonts Facts

Skinning a user interface with ScriptUI may be tricky as soon as you want to apply custom fonts to specific fields or controls. Besides the ScriptUI object model does not offer intuitive solutions to that purpose, we also have to cope with a few cross-platform issues…

Continue reading...

ExtendScript RegExp Tester

Test your Regular Expressions in ExtendScript

Continue reading...

How to Detect a “Ghost Item”

A “ghost item” is an anchored / inline page item (text frame, spline item, etc.) which is temporarily hidden because its parent character is in an overset area:

Example of ‘ghost’ anchored item.

Continue reading...

What Exactly is a Word?

A number of InDesign scripts manipulate words for counting, indexing, or other processing purposes. Given a text container—basically a Story—the InDesign Scripting DOM provides many ways to handle text contents through specialized subclasses of the Text interface: one can easily access to insertion points, character ranges, lines, paragraphs, text columns, styled-text chunks, and… words. Although this concept seems pretty straightforward, I tried to understand a bit better what it really means.

Continue reading...

Notes on ‘fastEntireScript’ Undo Mode

In April 2009, Thomas Silkjær reported a bug on app.doScript that alters the ‘undo’ feature in InDesign. Although this issue has been fixed in CS5, there are still some pitfalls to beware of when you want to speed up your script through fastEntireScript

Continue reading...

- Page 1 of 2