Monday, March 02, 2009

Scripting resources for InDesign

Adobe InDesign is fully scriptable, which means that anyone with a knowledge of basic programming skills with a language such as JavaScript, AppleScript or Visual Basic can learn to customize InDesign to automate repetitive or complex tasks.

I do quite a bit of InDesign script development for clients. JavaScript is my tool of choice, since it is cross-platform, working well on both Macintosh or Windows versions of InDesign.

I'm often asked for resources on how to get started learning how to program with JavaScript in InDesign. I wish there was a really good book I could recommend. But instead, you'll have to dig through the resources below:

Start by downloading these four critically important PDF files, published by Adobe, about scripting InDesign CS4:
Adobe Introduction to Scripting (CS4)
Adobe InDesign CS4 Scripting Tutorial
Adobe InDesign CS4 Scripting Guide: JavaScript
JavaScript Tools Guide (CS4)
Sample scripts that accompany the tutorials and guides above can be downloaded here.

Here are the equivalent PDF files for InDesign CS3:
Adobe Introduction to Scripting (CS3)
Adobe InDesign CS3 Scripting Tutorial
Adobe InDesign CS3 Scripting Guide: JavaScript
JavaScript Tools Guide (CS3)
Sample scripts that accompany the tutorials and guides above can be downloaded here.

There's a little bit of information about scripting in Adobe's online Help for InDesign [CS4].

Next, bookmark the InDesign Scripting forum on Adobe's Web site. This is a great place to learn from others about perplexing scripting questions.

Scripting InDesign with JavaScript by Peter Kahrel is the only recent book I've found that covers the JavaScript DOM (Document Object Model) for InDesign specifically. I highly recommended this book, available only as a downloadable PDF. Written for CS2, but most of the information is still relevant to CS3/CS4.

JavaScript: The Definitive Guide is a good general reference guide to the JavaScript programming language.

Dave Saunders, a prolific and talented scripter, posts occasionally to his JavaScripting InDesign blog.

Steve Wareham runs a blog where offers tutorials on how his various scripting projects were created.

Peter Kahrel, another prolific and very talented scripter, has several free scripts on his Web site. A good way to learn scripting is to examine and modify scripts written by others.

More scripts, both free and otherwise, can be found on Adobe's InDesign Exchange.

Happy scripting!


Lindy M said...

Great set of links here. BTW, Peter Kahrel's excellent book on Scripting InDesign with JavaScript has just been updated to CS3/4. Even better value at $10 for the PDF at O'Reilly.

guen gn said...

Is there a way to apply data merge field to textframes using script? I have been looking to do this but could not find any resource on the web. Thanks!

Uberdada said...

I decided to learn Javascripting for InDesign and downloaded the CS5 tutorial. However some of the example scripts it supplies don't work (eg. ImprovedHelloWorld). Looking at the CS4 tutorial it looks identical. Is there a difference between CS4 & 5 in the way the use Javascripts? If so it is frustrating that the tutorial isn't up to date.

Keith Gilbert said...

@Uberdada: There are slight differences in the scripting model between CS4 and CS5. But those differences shouldn't affect the simple tutorial scripts like "Improved Hello World". And, as far as I know, the tutorial is up to date for CS5. I suspect that something else is going on.

Anonymous said...

Uberdada is correct. The ImprovedHelloWorld example (CS5.5 tutorial) throws several errors and doesn't work. What gives?

Uberdada said...

If I remember correctly; myPage and myDocument are the wrong way round somewhere in the pdf document. Hope that helps.

Anonymous said...

Yep, ImprovedHello does throw several errors... Fustrating naw... When example tutorials from a vendor dont work it jus destroys all credability and lets one know StayAway! Just move on...

Paul said...

Absolutely annoying! So, I found the specific change and hope that it helps people progress through the tutorial. Find the following line in the script you copied from the pdf:

var myBounds = myGetBounds(myPage,myDocument);

Notice that myPage comes before myDocument. Switch those two and it works. So it should be:

var myBounds = myGetBounds(myDocument,myPage);

Keith Gilbert said...

Another great scripting resource: A new video training course I just recorded for "InDesign Scripting Made Easy" see