Showing posts with label Indesign scripting. Show all posts
Showing posts with label Indesign scripting. Show all posts

Monday

Create a new Indesign document using Javascript

First of all, Javascript is case sensitive, so if you're following along and reusing my code, make sure to be consistent with how you use uppercase and lowercase letters, for example, 'Indesign' and 'InDesign' are two different words in code.

So lets make a start and write some code.

Fire up the ExtendScript Toolkit (ESTK), type in #target indesign


image of ESTK with '#target indesign' typed into code window
















and hit F5 (Cmd+R on a Mac) to run it.

Indesign should start up if it isn't already running and give you this prompt, if so, tick the 'Don't show again' box and click Yes.


Prompt asking 'Do you want to launch Adobe Indesign CS4'












Now, go back to the ESTK and on the next line, type
#target indesign
alert("Hello world");

Hit F5 (Cmd+R on a Mac) and you should see


Alert dialog box showing 'Hello world' in Indesign


Congrats, you've just written your first script. But let's not stop there, our goal here is to actually create a new document, so add this line

#target indesign
alert("Hello world");
app.documents.add();

Hit F5 (Cmd+R) and BAM you have your new document. Party Time!

That's it for now, next time I'll show you how to save and name your document.

johnt

Sunday

Save and name your indesign file

Now that you're able to create an Indesign document, lets save and give it a name.

But firstly, seeing the "Hello world" prompt gets boring very quickly, you can either comment it out by adding // to the beginning of the line and it will be ignored, or you can just delete it.

#target indesign
//Now you know how to add comments to your code
//alert("Hello world");
app.documents.add();


Ok, back to saving and naming your file in one go. Just add
#target indesign
//Now you know how to add comments to your code
//alert("Hello world");
app.documents.add();
app.documents[0].save();

Hit F5 (Ctrl+R on a mac) to run it.

Screenshot of the Save dialog box














Notice the [0] attached to app.documents[0].save(); this is important as you may have many documents open so you need to tell Indesign to use document 0, which is how counting in javascript works, [0] equals item1, [1] equals item2, [2] equals item3, and so on.

Next, we'll create a text frame and add content to it.

Saturday

Adobe Indesign automation using Javascript

A little bit about me

I have been using Javascript to automate Indesign for a couple of years now, and I feel like I’m finally overcoming the initial hurdles of learning basic programming concepts, how to think logically about a computing problem, and how to express the solution through code.

I don't have a programming background so trying to find online resources that are easy to understand and digest is quite hard and frustrating. Often, there is technical jargon and assumed knowledge that most coding related websites use, even the ones aimed at people like me, who are new to programming.

Since the pain and frustration is still fresh in my memory, I’m going to use this blog as a way to document what I have learned so far and hopefully help anyone else who is just starting out in programming.

I’m still using Indesign CS4/6 but from what I have read, not much has changed in regards to scripting in the current version of Indesign. I primarily do my work on a Win7 computer, but I have access to a Mac, so I hope to cover both platforms and highlight their differences.
I aim to give short tutorials on how to perform specific tasks via scripting, I'll start with creating a simple Indesign document with a few pages of formatted text and perhaps go all the way up to creating a whole book, with styles, master pages, templates. Along the way, maybe cover how to automate repetitive tasks such as find/change, inserting new content and formatting text.
Please leave a comment if I cover something that is now out of date or incorrect and I’ll make amends.
Thanks.
johnt