Indiscripts

Tips

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

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

Operator Overloading with ExtendScript

Operator overloading in JavaScript is a controversial issue. Actually, this dangerous feature has been rejected in ECMAScript 4. However, ExtendScript allows you to override the behavior of many mathematical and logical operators on a class-by-class basis since CS2.

Continue reading...

Binary JavaScript Embedment (CS4/CS5)

The jsxbin format (“Binary JavaScript”) is a boon for developers because it enables them to distribute a script without exposing its precious code. The ExtendScript ToolKit (ESTK) offers an Export to Binary feature which instantly converts a human-readable js(x) file into jsxbin. InDesign can then interpret this file as if it were a pure JavaScript. The only (boring!) problem is that the encoded script is not allowed to load a persistent session through the #targetengine directive. Here is a secret trick to bypass this limitation with a single encrypted file.

Continue reading...

How to Create your Own InDesign Menus

The InDesign Menu Model.

Continue reading...

Can InDesign Script Rewrite Itself?

As illustrated by the YALT technique, it's easy —and powerful!— to let a script read its own bytes while it is running. We could even go further and get a script to update itself to achieve some advanced functionalities.

Continue reading...

Work Around the Width/Height Gap

Believe me or not, the InDesign DOM can't return directly the width and the height of a page item frame! Scripting beginners may be confused about this gap. There are many pitfalls to be aware of when we deal with dimensions and units. Let's talk about bounds and coordinate spaces...

Continue reading...

How to Quickly Test a Sample Code

Sometimes you just need to test a short snippet without having to create and install a complete script. Suppose you want to check some object properties, or to evaluate a simple JavaScript expression. It is easy to write and interprete your instructions from the ExtendScript Toolkit, but it would be even faster to do the whole job from the InDesign user interface.

Continue reading...

Type your Code

JavaScript is often considered as a weakly typed language. It means —among other things— that we don't need to tell explicitly what kind of variables we handle, or what kind of arguments we provide to a given function. String? Integer? Boolean? In most cases, everything will work without ever declaring the type.

Continue reading...

Page 2 of 2 -