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…
Tips
Scripters corner: howtos, tips and tricks for automating complex InDesign tasks.The Tricky Side of `string.replace( )` in ExtendScript
September 14, 2020 | Tips | en
Why You Should Never Use `x==null` in ExtendScript
May 13, 2020 | Tips | en
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…
How To Get parseInt( ) Fixed in ExtendScript
January 10, 2019 | Tips | en
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…
Note on ScriptUI Mouse Events
December 19, 2018 | Tips | en
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.
SelToPng | Quick InDesign-to-PNG Serializer
November 06, 2017 | Tips | en
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…
Coordinate Spaces & Transformations in InDesign — Chap.4 (Draft)
June 14, 2016 | Tips | en
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.
Why I Do Not Use Meaningful Variable Names (Anymore)
May 03, 2016 | Tips | en
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
…
On Dichotomic Divide-and-Conquer Algorithms
March 12, 2016 | Tips | en
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…
Coordinate Spaces & Transformations in InDesign — Chap.1-3
October 18, 2015 | Tips | en
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…
Reconsidering Array.sort( ) in ExtendScript/JavaScript — Part 2
May 20, 2015 | Tips | en
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…
Reconsidering Array.sort( ) in ExtendScript/JavaScript — Part 1
May 13, 2015 | Tips | en
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?
How to Operate IndexMatic & BookBarcode in InDesign CC
December 01, 2014 | Tips | en | fr
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…
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…
‘Sprite’ Buttons in ScriptUI [UPDATE]
July 05, 2013 | Tips | en
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…
Making String.split() support U+0000 in ExtendScript CS4
January 31, 2013 | Tips | en
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.
How to Augment and Process Nested Groups (CS4-CS6)
October 22, 2012 | Tips | en
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.
The Shortest-Ever Aphorism Generator
September 12, 2012 | Tips | en
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?
« previous entries - Page 2 of 3 - next entries »