In last week’s post we explored one way you could make the transition to using InCopy as the text editor of choice for your users. It involved using a simple script to access files from a pre-determined common folder. The simple act of being able to use a keyboard shortcut to access a file instead of folder diving can make a difference in how the user may respond to a change in workflow. You can make the new workflow even more acceptable by including placeholder text as part of each story.

To provide the placeholder text, your workflow will need to include some kind of naming convention to be used for your paragraph styles. For example your could have seven main style designations:

  • Banner (will span all columns)
  • Headline (May span column, usually is set in a point size from 24 to 36 point)
  • Quickread (Set off by using a different style of text, often italic)
  • Byline (Usually set in a bold style)
  • Dateline (Set in a style smaller than the Byline)
  • First (The first paragraph of the main text flow featuring a large drop cap)
  • Body (The style used for the main text)

To connect these styles together, the next paragraph style attribute is set to define each next style in the style “chain.” To indicate that a style has a “next” style, our example uses the convention of following the name of the style followed by an underscore and the name of the next style in the chain; as in:


To add the placeholder (dummy) text to a story, the designer first makes sure there is an active insertion point in the story’s first text container. When the script is run, the user chooses the first paragraph style in the desired style pattern. The script picks up each style in the chain, inserts text for each style, and styles the text.

The following discusses each step of the script.


The handler used is an old favorite. It returns a reference to document 1 for the application if it exists. In previous versions of InDesign, an open modal dialog will cause a script to error; however in the CC version this is no longer the case. You may want to include a test for an open modal dialog, just in case.


A handler checks for a selection and then determines if the first item of the selection is an insertion point.


A custom dialog is then presented to the user with a list of paragraph styles and user names to choose from. For demonstration, our sample script has the names hard-coded at the top of the script. For a real-world solution, the names could be returned from a database or similar data resource. The result of the dialog is used to create the placeholder text.


The paragraph styles from which the user chooses are restricted to just those that have an underscore as part of the name indicating that the style has a next style. Another way the chained paragraph styles could be differentiated might be by giving the styles a specific label. In either case, the next style property of the selected style allows the script to create a list of the styles to be used for the dummy text. The code to do this is shown below:


on getStyleChain (docRef, thisName)
   --initialize the value of the variable nextStyleName 
   set nextStyleName to missing value
   --initialize the variable for the list of styles
   set styleList to {}
   ---initialize a counting variable to be used to restrict number of iterations 
   tell application "Adobe InDesign CC"
      --add style chosen to the list
      set end of styleList to thisName
      --get a reference to the style using its name
      set paraStyleRef to paragraph style thisName of docRef
      --get the next style in the chain
      set nextStyle to next style of paraStyleRef
      --get the name of the next style
      set nextStyleName to name of nextStyle
      --repeat through the styles placing a reference to each in the list
      repeat while nextStyleName is not equal to thisName
         set paraStyleRef to paragraph style nextStyleName of docRef
         set thisName to name of paraStyleRef
         set end of styleList to thisName
         set theCounter to theCounter + 1
         if theCounter is greater than 10 then
            exit repeat
         end if
         set nextStyle to next style of paraStyleRef
         set nextStyleName to name of nextStyle
      end repeat
   end tell
   return styleList
end getStyleChain


var thisName = "Head24_Byline" ; //returned from dialog
var docRef = app.documents.item(0);
//initialize variables
var nextStyleName = undefined;
var styleArr = [];
var theCounter = 0;
//add first style to array
styleArr.push (thisName);
//get reference to style using its name
var paraStyleRef = docRef.paragraphStyles.itemByName(thisName);
//get the next style property for the current style
var nextParaStyle = paraStyleRef.nextStyle;
//get the name of the next style
var nextStyleName =;
//repeat within a while loop
while (nextStyleName != thisName){
   paraStyleRef = docRef.paragraphStyles.itemByName(nextStyleName);
   thisName =;
   theCounter ++;
   //prevent an infinite loop in event of error
   if (theCounter > 10) {
   nextParaStyle = paraStyleRef.nextStyle;
   nextStyleName =;


Based on the list of paragraph style names, a corresponding list of text is created. This is done within a repeat loop similar to the following:


set dText to {}
repeat with i from 1 to length of styleChain
if item i of styleChain contains "Banner" then
set end of dText to "Banner Headline Here"
else --and so on
end repeat


var styleChain = ["Head24_Byline","Byline","Dateline","First","Body"];
var dText = [];
for (var i = 0; i < styleChain.length; i++) {
    if (styleChain[i].indexOf("Headline") > -1) {
       dText.push ("Headline Here");
    } else if (styleChain[i].indexOf("Byline") > -1) {
         dText.push ("Byline Here");
    } // and so on


The list of text and list of paragraph styles are then used for inserting at the selected insertion point. The code to style the inserted text can pose a problem. The process starts by getting the index of the selected insertion point. The index of the insertion point at the end of the inserted text is calculated by adding the length of the text to the index of the beginning insertion point. Using the two insertion points, a reference to the text placed is determined and the paragraph style is applied in part as follows:


tell application "Adobe InDesign CC"
set docRef to document 1 
set paraStyleRef to paragraph style "Head24_Byline" of docRef
set selList to selection
if length of selList > 0 and class of item 1 of selList is insertion point then
   set insertRef to item 1 of selList
   error ("Requires selection point reference")
end if
--story reference is parent story property of insertion point
set storyRef to parent story of insertRef
set beginIndex to index of insertRef --index of selected insertion point
set endIndex to beginIndex + (length of dText) --dText is text inserted
--get reference to text inserted; notice the use of a reference to
set textRef to (a reference to characters beginIndex thru endIndex of storyRef)
--apply the paragraph style to the text
set applied paragraph style of textRef to paraStyleRef
end tell


var docRef = app.documents.item(0);
var paraStyleRef = docRef.paragraphStyles.itemByName("Head24_Byline");
var selArr = app.selection;
var insertRef = undefined;
var dText = "Headline Here" + "\n";
if (selArr.length > 0 && selArr[0] == "InsertionPoint") {
 insertRef = selArr[0];
} else {
   error ("Requires insertion point selection");
var storyRef = insertRef.parentStory;
var beginIndex = insertRef.index;
insertRef.contents = dText;
var beginTextRef = storyRef.characters.item(beginIndex);
var endIndex = beginIndex + dText.length;
var endTextRef = storyRef.characters.item(endIndex);
var textRef = storyRef.texts.itemByRange(beginTextRef, endTextRef);
textRef.applyParagraphStyle(paraStyleRef, true);

As you can see, there is a fair amount of code needed to perform this seemingly simple task. Over a period of time, it can save the designer a considerable amount of effort and make the task of the copywriter much easier.

In next week’s post, we will look at how a script can be used to automate the actual process of creating an assignment and assigning stories.