Indiscripts

Tips

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

Porting your InDesign Script into IdExtenso — Step 2

Today we will embed in IdExtenso the code we prepared in the previous episode. That's of course an important move, especially when you perform it for the very first time (since then you need to install the framework.) But you will discover in what follows the immediate advantages that $$ offers you…

Continue reading...

Porting your InDesign Script into IdExtenso — Step 1

So, you have the root idea and a basic code for your next InDesign script. All is fine. It works so well that you're now planning to release it, which opens additional questions: Will it work everywhere? How do I trace risky functions? What if I need to integrate new features later on? How do I deal with persistent user settings? How to add a basic interface? How will I localize the dialog in other languages? Can I make my script available in a dedicated menu? Will it work in a JSXBIN package as well? Can I obfuscate my code?…

Continue reading...

Page Range Formatter [UPDATE]

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

The Cell Tint Enigma

How do Tint objects operate at the Cell level?

Continue reading...

ScriptUI vs. UI Scaling

From CC 2014, InDesign and Illustrator interfaces needed to adapt to OS “scale settings” strategy on 4K/Retina displays. And with Windows 10 defaultly scaling at 150% in such resolutions, Adobe engineers were forced to rework their famous HiDPI support, which led to introduce UI Scaling in the Preferences dialog box. So far, so good. But ScriptUI has not been fully “informed” of these new rules…

Continue reading...

Understanding the `count( )` Method

InDesign's scripting infrastructure is based on DOM objects (Document, Story, Paragraph…) and any such object has an associated collection (Documents, Stories, Paragraphs…). Collections typically arise in complex specifiers like myDocument.stories.everyItem().words. They also provide two essential members, the length property and the count() method. How do they differ?

Continue reading...

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

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

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

Six years! It tooks me six years to document the fundamentals of InDesign “Coordinate Spaces and Transformations.” You may think I am sluggishly slow—which is a sensible diagnosis!—but the topic required a true immersion to be both experimented and covered. Chapter 5 (“The Transform Process”) is now available and makes this version 3.1 consistent enough to form a kind of white paper

Download version 3.1 (PDF, 40 pages)

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.

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…


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

- Page 1 of 3