TweetFollow Us on Twitter

Introduction to Scripting InDesign

Volume Number: 22 (2006)
Issue Number: 11
Column Tag: AppleScript Essentials

Introduction to Scripting InDesign

by Benjamin S. Waldie

In last month's column, we discussed scripting page layout applications in order to automate your desktop publishing workflow. Specifically, we focused on getting started with scripting QuarkXPress <>. This month, we will be discussing another popular and well-known page layout application, Adobe InDesign <>.

Getting Started

Before we begin scripting InDesign, I'd like to briefly discuss InDesign's AppleScript support. When you open InDesign's dictionary for the first time, one of the things you may notice is that it is quite long. See figure 1.

Figure 1. InDesign's AppleScript Dictionary

InDesign contains extensive AppleScript support for automating almost anything that you can do manually. Sure, you may come across a feature here and there that doesn't have corresponding AppleScript support. However, these situations are certainly few and far between. Furthermore, InDesign's AppleScript support is constantly being revised, improved, and expanded with each new release of the application, so it just keeps on getting better.

Working with Documents

Within InDesign, you will most likely want to automate tasks that involve documents, so that is what we will focus on here. If you need to automate books, you are encouraged to explore InDesign's dictionary for the functionality you require.

Referring to Documents

A document is referenced using the document class, which can be found in the Basics Suite, in InDesign's dictionary. Documents may be referenced using their index (front to back positioning) or by their name. The following example code demonstrates how a document would be referenced using its index.

tell application "Adobe InDesign CS2"
   tell document 1
      -- Do something
   end tell
end tell

Similarly, the following code would reference a document by its name.

tell application "Adobe InDesign CS2"
   tell document "My Document.indd"
      -- Do something
   end tell
end tell

In most cases, unless you will always only have one document opened in InDesign, it is usually the safest to refer to a document by its name. This way, if the front to back positioning of a document changes, your script will continue to target the correct document.

Throughout this month's column, however, we will be referring to documents by their index. Specifically, we will reference document 1, which will refer to the frontmost document. Another way to target the frontmost document is to reference the active document property of the application class. For example:

tell application "Adobe InDesign CS2"
   tell active document
      -- Do something
   end tell
end tell

Checking for the Existence of a Document

Before your AppleScript begins interacting with a document, it is often a good idea to make sure that the document exists. This may be done using the exists command, as follows.

tell application "Adobe InDesign CS2"
   document 1 exists
end tell
--> true

As the example code above demonstrates, the result of the exists command is a true or false Boolean value indicating whether or not the document exists.

Creating Documents

Depending on your workflow, you may not need to work within an existing document, but within a new document. To create a new document via AppleScript, use the make command, as demonstrated below.

tell application "Adobe InDesign CS2"
   make new document
end tell
--> document "Untitled-1" of application "Adobe InDesign CS2"

The result of the make command is a reference to the newly created document, which may be placed in a variable and referenced later in order to perform additional tasks within the document.

Please note that in the example code above, we did not specify the size of the document to be created. In this situation, the document would be created using InDesign's default document size. To specify a size for the document, you may optionally specify values for the page width and page height properties, which are actually properties of the document preferences property of the document class. Here is an example of how this would be done:

tell application "Adobe InDesign CS2"
   make new document with properties {document preferences:{page width:8.5, page height:11}}
end tell
--> document "Untitled-1" of application "Adobe InDesign CS2"

Again, make note of the example code above. Here, although we have specified a size for the document, we have not specified unit of measurement, i.e. inches, points, centimeters, millimeters, etc. Because of this, the default unit of measurement will be used when creating the document. In other words, if InDesign's default unit of measurement is set to inches, then an 8.5" x 11" document would be created.

You may optionally choose to specify the unit of measurement when creating the document, as demonstrated below.

tell application "Adobe InDesign CS2"
   make new document with properties {document preferences:{page width:"8.5in", page height:"11in"}}
end tell
--> document "Untitled-1" of application "Adobe InDesign CS2"

Another way to ensure that the proper unit of measurement will be used when the document is created is to modify the default unit of measurement. This is done by setting the value of the horizontal measurement units and vertical measurement units properties of the document's view preferences to the desired unit type. For example, the following sample code will set the default unit of measurement to inches, and then create the document, ensuring an 8.5" x 11" document.

tell application "Adobe InDesign CS2"
   tell view preferences
      set horizontal measurement units to inches
      set vertical measurement units to inches
   end tell
   make new document with properties {document preferences:{page width:8.5, page height:11}}
end tell
--> document "Untitled-1" of application "Adobe InDesign CS2"

Since InDesign's default unit of measurement may vary from user to user, changing the default unit of measurement to the desired value at the beginning of an InDesign-specific AppleScript is usually good practice. In addition to ensuring that a newly created document will be the correct size, specifying the default unit of measurement at the beginning of your script will help to ensure that resizing or creating other elements, such as text frames, rectangles, etc., will be done using the desired unit of measurement.

Working with Text

Developers that are automating InDesign will often have the need to interact with text frames in InDesign documents, whether that need is to insert text, extract text, format text, or more. We will now discuss a number of ways to interact with text frames in InDesign.

Creating a Text Frame

First and foremost is creating new text frames. This will be necessary if you intend to add text to a newly created document.

Before creating a text frame, the first thing you will want to do is identify where the text frame will be created, and how large it will be. Once you have determined this information, you will need to translate it into a list of bounds, which can be specified via AppleScript when the text frame is created. Bounds of a text frame will be specified as a list of four items, formatted as follows:

{top position, left position, bottom position, right position}

Once you have determined the desired bounds for a text frame, use the make command to create the text frame. In doing so, specify the bounds for the text frame using the geometric bounds property of the text frame, as demonstrated below.

tell application "Adobe InDesign CS2"
   tell page 1 of document 1
      make new text frame with properties {geometric bounds:{1, 1, 3, 6}}
   end tell
end tell
--> text field id 191 of page id 159 of spread id 154 of document "Untitled-1" of 
   application "Adobe InDesign CS2"

Assuming that the default unit of measurement is set to inches, the code above would create a 5" x 2" text frame that is 1" down and 1" across on the first of page of the frontmost document.

Placing Text

Now that you have a text frame, you are ready to insert text into it. To insert text into a text frame, replacing any existing content, set the contents property of the text frame's parent story to the desired text.

tell application "Adobe InDesign CS2"
   tell parent story of text frame 1 of page 1 of document 1
      set contents to "My Project Text"
   end tell
end tell

It is also possible to insert text into a specific location within a text frame, appending it to existing text. This is done by setting the contents property of a specified insertion point within the parent story of the text frame to a specified value. For example, the following code would append the text "My Project Text" to the end of any existing text within the specified text frame, without replacing the existing text.

tell application "Adobe InDesign CS2"
   tell parent story of text frame 1 of page 1 of document 1
      set contents of insertion point -1 to "My Project Text"
   end tell
end tell

Styling Text

Text in InDesign possesses numerous properties, including font, point size, color, and much more, which are accessible via AppleScript. The following example code demonstrates one way that these properties could be modified. This particular code will set the font of the text within the specified text frame to "Arial", the point size of the second word to 24, and the color of the first three words to specified values.

tell application "Adobe InDesign CS2"
   tell parent story of text frame 1 of page 1 of document 1
      set applied font to "Arial"
      set point size of word 2 to 24
      set fill color of word 1 to "C=0 M=0 Y=100 K=0"
      set fill color of word 2 to "C=100 M=0 Y=0 K=0"
      set fill color of word 3 to "C=0 M=100 Y=0 K=0"
   end tell
end tell

Please note that, in the above example, the colors specified correspond to the names of colors in InDesign's Swatches palette. See figure 2.

Figure 2. InDesign's Color Swatches Palette

Figure 3 shows the result of executing the previous code on a text frame that contains the text "My Project Text".

Figure 3. Styled Text in InDesign

Working with Graphics

Interaction with graphics is often another important aspect of scripting InDesign. In InDesign, graphics are typically placed within rectangles. However, it is also possible to place them into text frames. For the sake of reducing confusion, in this column, we will discuss working with graphics in rectangles.

Creating a Graphic Frame

Like text frames, rectangles may be created via AppleScript by using the make command, and specifying the desired bounds for the rectangle. For example, assuming the default unit of measurement is set to inches, the following code would create a 3" x 5" rectangle 1" across and 3" down.

tell application "Adobe InDesign CS2"
   tell page 1 of document 1
      make new rectangle with properties {geometric bounds:{3, 1, 6, 6}}
   end tell
end tell
--> rectangle id 385 of page id 159 of spread id 154 of document "Untitled-1" of 
   application "Adobe InDesign CS2"

Again, here, the result of the make command is a reference to the newly created rectangle.

Placing a Graphic

Once a rectangle exists, the place command may be used to place a graphic within the rectangle. The place command requires a reference to the graphic file to be placed. For example:

set theImage to choose file with prompt "Please select an image to place:" without 
tell application "Adobe InDesign CS2"
   tell rectangle 1 of page 1 of document 1
      place theImage
   end tell
end tell
--> image id 391 of rectangle id 385 of page id 159 of spread id 154 of document "Untitled-1" of 
   application "Adobe InDesign CS2"

Here, the result of the place command is a reference to the newly placed image, within the rectangle. Figure 4 shows an example of a placed graphic within a rectangle on an InDesign document page.

Figure 4. A Placed Graphic

Labeling Page Items

Throughout this column, we have referenced text frames and rectangles by index. When we discussed referencing documents, I mentioned that a more accurate way of referring to documents was by name. The same rule applies to text frames, rectangles, and other page items within InDesign documents. The reason for this is that, if a new page item is created, or page items are repositioned within the document, the index of a page item may change.

To always ensure that your script is referencing the correct page item, you may apply a script label to the item. This may be done via AppleScript, for example:

tell application "Adobe InDesign CS2"
   tell text frame 1 of page 1 of document 1
      set label to "myTextFrame"
   end tell
end tell

Applying script labels to page items may also be done manually within InDesign by using the Script Label palette, which can be made visible via the Window > Automation menu. See figure 5.

Figure 5. InDesign's Script Label Palette

Once a script label has been applied to a page item, you may reference it by that label, rather than by its index. For example:

tell application "Adobe InDesign CS2"
   tell text frame "myTextFrame" of page 1 of document 1
      -- Do something
   end tell
end tell

Next Steps and Resources

Documentation and Support

If you plan to continue scripting InDesign in order to automate processes in your own workflow, there are a number of resources available to you for continued learning.

First and foremost, Adobe provides detailed documentation for scripting InDesign. A very comprehensive InDesign Scripting Reference and InDesign Scripting Guide may be downloaded from the Adobe website at <>. These documents contain extensive documentation with regard to all of InDesign's scripting features, and will no doubt prove to be an important addition to any InDesign scripter's arsenal.

The online Adobe support forums at <> are a tremendous resource for anyone using or scripting InDesign, or any other Adobe application for that matter. Here, you will find numerous application-specific forums, including the InDesign Scripting forum, where you may post your questions to other InDesign scripters.

Expanding InDesign's AppleScript Support

While InDesign's AppleScript support is quite extensive, there's always room for improvement, right? Well, with InDesign's plug-in architecture, it is actually possible to expand its AppleScript support with the addition of scriptable plug-ins. There are numerous scriptable plug-ins available for InDesign, including InCatalog and InData, available from Em Software (, which can be used to automate many complex data-driven publishing tasks. For a list of many available InDesign plug-ins, visit the InDesign plug-ins page on Adobe's website at Also, be sure to check out the Adobe Studio Exchange at

In Closing

For those desktop publishers currently using InDesign and looking to become more efficient, hopefully, this month's column has helped to shed some light on the possibilities. Be sure to continue exploring InDesign's AppleScript support on your own, and don't forget to check out the resources that I have mentioned above.

Until next time, keep scripting!

Ben Waldie is the author of the best selling books "AppleScripting the Finder" and the "Mac OS X Technology Guide to Automator", available from, as well as an AppleScript Training CD, available from Ben is also president of Automated Workflows, LLC, a company specializing in AppleScript and workflow automation consulting. For years, Ben has developed professional AppleScript-based solutions for businesses including Adobe, Apple, NASA, PC World, and TV Guide. For more information about Ben, please visit, or email Ben at


Community Search:
MacTech Search:

Software Updates via MacUpdate

FileMaker Pro 19.4.2 - Quickly build cus...
FileMaker Pro is the tool you use to create a custom app. You also use FileMaker Pro to access your app on a computer. Start by importing data from a spreadsheet or using a built-in Starter app to... Read more
Adobe Illustrator 26.0.3 - Professional...
You can download Adobe Illustrator for Mac as a part of Creative Cloud for only $20.99/month. Adobe Illustrator for Mac is the vector graphics classics in the design industry. It is a digital... Read more
WhatRoute 2.4.9 - Geographically trace o...
WhatRoute is designed to find the names of all the routers an IP packet passes through on its way from your Mac to a destination host. It also measures the round-trip time from your Mac to the router... Read more
Notion 2.0.20 - A unified workspace for...
Notion is the unified workspace for modern teams. Notion Features: Integration with Slack Documents Wikis Tasks Release notes were unavailable when this listing was updated. Download Now]]> Read more
Monterey Cache Cleaner 17.0.2 - Clear ca...
Monterey Cache Cleaner is an award-winning general-purpose tool for macOS X. MCC makes system maintenance simple with an easy point-and-click interface to many macOS X functions. Novice and expert... Read more
Firetask Pro 4.6.8 - Innovative task man...
Firetask Pro represents the next generation of easy-to-use, project-oriented task management apps. By combining David Allen's powerful Getting Things Done (GTD®) approach with classical task... Read more
Smultron 13.0.4 - Easy-to-use, powerful...
Smultron 13 is the text editor for all of us. Smultron is powerful and confident without being complicated. Its elegance and simplicity helps everyone being creative and to write and edit all sorts... Read more
Box Sync 4.0.8057 - Online synchronizati...
Box Sync gives you a hard-drive in the Cloud for online storage. Note: You must first sign up to use Box. What if the files you need are on your laptop -- but you're on the road with your iPhone? No... Read more
Audio Hijack 3.8.10 - Record and enhance...
Audio Hijack (was Audio Hijack Pro) drastically changes the way you use audio on your computer, giving you the freedom to listen to audio when you want and how you want. Record and enhance any audio... Read more
Direct Mail 6.0.1 - Create and send grea...
Direct Mail is an easy-to-use, fully-featured email marketing app purpose-built for macOS. Create, send, and track great looking email campaigns that get results. Start your newsletter by selecting... Read more

Latest Forum Discussions

See All

SwitchArcade Round-Up: ‘Pokemon Legends:...
Hello gentle readers, and welcome to the SwitchArcade Round-Up for January 28th, 2022. We’ve got a bunch of new releases to look at today, with a few big hitters, a few mid-level diversions, and a healthy supply of compost. Since it’s Friday, we... | Read more »
Phantom Blade: Executioners, S-Game...
S-Game has kicked off its first Closed Beta Test for Phantom Blade: Executioners, inviting a selected few to get first dibs on the upcoming KungFuPunk action RPG on mobile. The CBT officially begins this January 28th, and beta testers will receive... | Read more »
‘Infinite Galaxy’ First Anniversary: Cel...
Cultivating a new generation of valiant commanders across 240 countries worldwide, Infinite Galaxy has quenched players’ thirst to explore the vastness of space – and there are only more intergalactic adventures to embark on from here on out. Camel... | Read more »
War and Order: How to brave the cold in...
War and Order's 6th-anniversary celebrations are underway, and all in good time too - this season not only brings about fabulous festivities, but it also lets players experience the harsh winter in an entirely new way. [Read more] | Read more »
‘Hidden Folks+’ Is This Week’s New Apple...
The original Hidden Folks from Adriaan de Jongh is an excellent hidden objects game featuring hand drawn visuals. It is an absolute joy to play, and it has now released on Apple Arcade in the form of Hidden Folks+ () as an App Store great. If you’... | Read more »
Mini Metro’s First Big Update of 2022 Ad...
Last year saw great updates for Dinosaur Polo Club’s Mini Metro ($3.99) which is also available on Apple Arcade as an App Store Great. | Read more »
SwitchArcade Round-Up: ‘Gunvolt Chronicl...
Hello gentle readers, and welcome to the SwitchArcade Round-Up for January 27th, 2022. In today’s article, we’ve got a whole bunch of new releases to check out. It’s a dangerous one for the wallet today, as there are several interesting games to... | Read more »
SIEGE: Apocalypse lets you engage in mil...
Launching today to the delight of military enthusiasts across the globe, SIEGE: Apocalypse is a new 1v1 military battler from KIXEYE that's set in the early days of the War Commander universe. Players need to collect and upgrade unit cards to build... | Read more »
‘SIEGE: Apocalypse’, KIXEYE’s Military-T...
Military fans across the globe now have more reasons to dive into the War Commander universe as KIXEYE launches SIEGE: Apocalypse on both iOS and Android devices today. The 1v1 military battler pits two players against each other in intense real-... | Read more »
‘Yu-Gi-Oh! Master Duel’ Is Rolling Out N...
Following its launch on PC and all consoles last week, Yu-Gi-Oh! Master Duel has finally released on mobile platforms. Since launch, the game has exploded on multiple platforms with it having over 260k concurrent players on Steam. It has full... | Read more »

Price Scanner via

Apple has clearance 2020 13″ MacBook Airs ava...
Apple has clearance, Certified Refurbished, 2020 13″ Intel-based MacBook Airs in stock today starting at only $719 and up to $370 off original MSRP. Each MacBook features a new outer case, comes with... Read more
The cheapest iPhones for sale today at Apple...
Apple has restocked Apple Certified Refurbished iPhone 8 models starting at only $359. Each refurbished iPhone comes with a fresh external case, standard Apple 1-year warranty, and free shipping.... Read more
14″ MacBook Pro with Apple M1 Max CPU now in...
Looking for a new 14″ MacBook Pro with an Apple M1 Max CPU? Stock is finally trickling into Apple resellers. B&H has Silver 14″ M1 Max MacBook Pros in stock today for $2899 including free 1-2 day... Read more
14″ MacBook Pros with Apple M1 Pro CPUs are i...
Amazon is reporting stock of 14″ MacBook Pros with M1 Pro CPUs today with a $50 discount. Shipping is free, and delivery is available by February 1st for most configurations. Be sure to make your... Read more
Apple has restocked 13″ M1 MacBook Pros for $...
Apple has restocked a full line of 13″ M1 MacBook Pros available Certified Refurbished, starting at only $1099 and up to $230 off original MSRP. These are the cheapest M1 MacBook Pros for sale today... Read more
Apple’s AirPods Max headphones are on sale fo...
Amazon has Silver, Blue, and Space Gray Apple AirPods Max headphones on sale today for $100 off MSRP. Shipping is free, and all models are in stock today. Their price is the lowest currently... Read more
Open a new line of service at Verizon and get...
Verizon is giving away 64GB Apple iPhone 12 minis or your choice of an iPhone 11 to customers who choose one of these phones and open a new line of service. Offer is available online only, and no... Read more
Open-box 13″ M1 MacBook Airs now available st...
QuickShip Electronics has open-box return 13″ M1 MacBook Airs in stock and on sale for $200-$400 off MSRP on their eBay store right now with free express delivery. According to QuickShip, “The item... Read more
Verizon’s 2022 iPad promo: $100-$310 off any...
Verizon has cellular-capable iPads on sale for $100-$310 off MSRP when purchased with an Unlimited service plan. Sale price is applied to your account monthly over a 24 or 30 month period, depending... Read more
Sunday Sale: Apple AirPods are on sale for up...
Amazon has Apple AirPods on sale for $10-$100 off MSRP today, depending on the model. All are in stock today with free delivery: – AirPods Max headphones (Blue): $449 $100 off MSRP – AirPods Max... Read more

Jobs Board

Registered Nurse (RN) Employee Health PSJH -...
…is calling for a Registered Nurse (RN) Employee Health PSJH to our location in Apple Valley, CA.** We are seeking a Registered Nurse (RN) Employee Health PSJH to be Read more
Systems Administrator - Pearson (United State...
…and troubleshoot Windows operating systems (workstation and server), laptop computers, Apple iPads, Chromebooks and printers** + **Administer and troubleshoot all Read more
IT Assistant Level 1- IT Desktop Support Anal...
…providing tier-1 or better IT help desk support in a large Windows and Apple environment * Experience using IT Service Desk Management Software * Knowledge of IT Read more
Human Resources Business Partner PSJH - Provi...
…**is calling a** **Human Resources Business Partner, PSJH** **to our location in Apple Valley, CA.** **Applicants that meet qualifications will receive a text with Read more
Manager Community Health Investment Programs...
…is calling a Manager Community Health Investment Programs PSJH to our location in Apple Valley, CA.** **Qualified candidates will be invited to do a self-paced video Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.