Indiscripts

Tips

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

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

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

Comparing the Performance of ExtendScript Snippets

Although jsPerf is a very effective tool in a pure JavaScript environment, you may want to benchmark competing code snippets in the specific ExtendScript field. Here is a simple way to test and improve your InDesign scripted functions…

Continue reading...

Permutation d'objets dans InDesign (miniscript)

Non sans témérité, Stéphane Baril et David Deraedt nous ont récemment accueillis sur le plateau de Chips & Tips, la célèbre série d'Adobe TV dédiée à la diététique productivité. Au détour de cet épisode, Loïc Aigon et votre serviteur proposons une sorte de préambule aux techniques d'automatisation et de scripting dans la Creative Suite, avec quelques illustrations simples et directement accessibles aux néophytes. Vous y découvrirez notamment la version embryonnaire du script SwapItems utilisé pour permuter des objets dans une maquette InDesign…

Continue reading...

How to Implement a Basic Action Listener in InDesign

While Photoshop has a handy Actions panel that gives you the ability to record and playback simple operations, InDesign provides no way —without scripting!— to automate those daily repetitive tasks. But, hey!, why not use a script to mimic such action manager? This is my very first step in that direction...

Continue reading...

Alphabetical Sort in JavaScript (and InDesign)

Surprisingly, JavaScript offers no easy way to alphabetize words in relevant order. Although the Array.sort() method is known to perform, by default, a lexicographical sort, you will find very quickly that the result is wrong in most real-life situations. Actually, the internal mechanism of JS sorting is confined to compare Unicode characters by their code points, so 'Z' (U+005A) comes before 'e' (U+0065), which itself comes before 'ç' (U+00E7), etc. Also, you have all noted with vexation that InDesign does not offer any alphabetical sort feature! Here is an experimental tool to help restore order in Latin alphabets.

Continue reading...

On ‘everyItem()’ – Part 2

In the previous episode we learned that every scripting DOM object is in fact an object specifier, which acts like a path in the InDesign object tree. Collection's methods only allow us to build object specifiers. Invoking a property or a method provided by a specifier causes InDesign to send a “verb-first command” to the underlying receiver(s). We will now consider how this process impacts your code, what is returned into your script and how to deal with some side effects.

Continue reading...

On ‘everyItem()’ – Part 1

Every collection in the scope of the InDesign Scripting DOM provides a method called everyItem. It remained undocumented until InDesign CS3, but scripting experts such as Dave Saunders had already pointed out its forcefulness and already knew how to exploit it. Here are some details about this esoteric syntax.

Continue reading...

- Page 2 of 3 -