Indiscripts

Automating InDesign since 2009

Tips

Scripters corner: howtos, tips and tricks for automating complex InDesign tasks.

The Tricky Side of `string.replace( )` in ExtendScript

When you invoke myString.replace(...) in pure JavaScript, the “string being examined” is and remains myString during the whole operation. ExtendScript offers a slightly different mechanism that may unexpectedly alter the output string…

Continue reading...

What's New in IdExtenso 2.00601

IdExtenso: ExtendScript Framework for InDesign Ninjas

Continue reading...

Why You Should Never Use `x==null` in ExtendScript

The Japanese scripter あるふぁ found a bug affecting any ExtendScript code based on ...==null. This is not a critical issue (because experienced developers never use such condition!) but the case provides the opportunity to summarize important rules regarding falsey values and the equality operator…

Continue reading...

On the Hidden “Em-Box” Option

A secret Baseline Option is available in InDesign…

Continue reading...

InDesign Swatches: Diagram

DOM Swatches: properties and relationships.

How To Get parseInt( ) Fixed in ExtendScript

The global method parseInt(str,radix) has a critical bug in ExtendScript. When radix is greater than 10, some undesired characters can be mistakenly parsed as valid digits, which corrupts the output. This issue is solved in IdExtenso

Continue reading...

Note on ScriptUI Mouse Events

ScriptUI provides a set of usual mouse events (mouseover, mousedown, mouseup, click…) which are of primary interest in responsive user interfaces (UI). Developers can add event listeners to any UI component that needs to respond accordingly when the mouse enters the scene. But handling such events requires carefulness if your script has to support both CS and CC environments.

Continue reading...

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.


Go to the newest release of this document

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…


Go to the newest release of this document

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

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

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

- Page 2 of 3 -