Templates to the Rescue

There should be no doubt that having access to a few well-designed templates can save some significant time when it comes to creating documents. A template serves as the foundation for the layout. To be effective it should contain the basic elements that are not anticipated to change, such as border, background items, logo, and perhaps contact information. Typically this information would be placed on master pages but if exporting to ePub you will want to place these items on layers.

The template should also contain a comprehensive collection of text and object styles to facilitate text and image frame styling.

Text Styles

When creating paragraph styles for a template be sure to base all styles using the most prevalent font on [Basic Paragraph]. As an example, all of your text styes with the exception of possibly headlines and a decorative style might use some variant of Minion Pro. Start by styling [Basic Paragraph] as Minion Pro Regular with no indents or space before or after. Additionally, you might decide to use a font size consistent with body text. Use names such as Headline, Byline, Sidehead, and Caption for your styles instead of names that specify the font or size as in Minion 12pt. This gives your template more flexibility. Should your next document specify using Myriad Pro, Garamond, or some other font style, all that may need to be changed would be the font for the [Basic Paragraph] style.

Object Styles

Take advantage of the fact that paragraph styles can be assigned to object styles for text containers. For example, a photo caption frame could have an object style named Caption assigned the paragraph style Caption. This will keep styling consistent even if styling changes are made to the styles in subsequent documents.

Chained Paragraph Styles

And don’t forget, if you have text style patterns that are consistent, set up style ““chains” using the Next Style property of a style. Assign the first member of the “chain” to a text container object style and your template will provide the means for automated text styling. To review how this would work, suppose the headlines in your document will always be followed by a drop cap paragraph with all subsequent text assigned the style Body. You first establish the style for Body, then DropCap, and finally Headline. With this done, you can now assign the Next Style for Headline to DropCap, and the Next Style for DropCap as Body. 

For this text container you could create an object style named HeadDropBody and enable its Paragraph Styles attribute. This attribute is then assigned the Headline style with Apply Next Style checked. 

Page Layout

You can add to a template’s extensibility by allowing master pages or scripts to assign layout style variants to pages as needed. For example, the pages for the sample document shown below were designed for a single text flow (Primary Text Frame checked in New Document dialog). The captioned image frames were then created using a script that presents a number of layout styles to choose from. Once the containers were created, a second script was used to name the containers consecutively to match the names of corresponding image files. When a third script is run, the containers are populated with the image and its metadata using the Description field for the file’s information (File Info).

A more popular use of a script for creating containers for page layout is for catalog pages where the containers are organized in a grid of rows and columns as shown in the example below. The script calculates the bounds for each of the containers based on the page item selected when the script is run.

Understanding that a catalog page could feature a single item or any number of items up to twelve (3 rows and 4 columns), using a script to automatically divide the product information area of the page makes a lot of sense. A simplified version of this script is our Feature Script for this month (see our AppleScript page).

Eliminate Folder Diving

Save your templates to a specific location on the computer hard drive. Using this location, a script can then create new documents using a chosen template. One location of choice for the Template folder is inside the folder for the application. This allows the script to create the path to the template folder using the application’s file path.

—call to handler to get path to Template folder
   set folderName to "Templates"
   set fileTypeList to {"IDm7", "ID7t", "ID8t", "ID9t", "IDXt"}
   set thePrompt to "Choose template file from list"
      set templatePath to getTemplatePath(folderName)
   on error errStr
      display alert errStr
   end try
(*Returns path to folder named residing in application folder; if folder not found error is raised*)
on getTemplatePath(folderName)
	tell application "Adobe InDesign CC 2014"
		set appPath to file path as string
		set templatePath to appPath & folderName
	end tell
        return templatePath      
end getTemplatePath

Using the path returned from the handler, the script then gets a list of the files in the folder. The call to this handler is placed inside the try block after the call to getTemplatePath(). Handlers are placed together at the bottom of the script.

 --call to handler to get list of files in the folder
   set fileList to getFiles(templatePath, fileTypeList)
   --returns list of file names found in folder by file type
   on getFiles(templatePath, fileTypeList)
	tell application "Finder"
		set templateNames to name of every file of folder templatePath whose file type is in fileTypeList
		return templateNames
	end tell
   end getFiles

The user then chooses the template from the list which the application uses to create the new document. The call to this handler is placed directly below the call to getFiles().

  --call to docFromTemplate handler
    if length of fileList is greater than 0 then
       set docRef to docFromTemplate(templatePath, thePrompt, fileList)
    end if
   --creates document from template chosen; if no file chosen error 
   on docFromTemplate(templatePath, thePrompt, fileList)
	set fileChoice to choose from list fileList with prompt thePrompt without multiple selections allowed
	if class of fileChoice is list then
		tell application "Adobe InDesign CC 2014"
			set docRef to open file (templatePath & ":" & fileChoice)
		end tell
		error "No document chosen"
	end if
   end docFromTemplate

The script can be modified as needed to define the location for your templates if your folder is located elsewhere. For a list of other standard locations on your computer that can be used for saving files, open the dictionary for StandardAdditions and enter Path to in the search field.

The file types defined for the variable fileTypesList should cover all templates from InDesign CS5.5 to InDesign CC 2014. If your script does not return a list of files, you may need to verify the file type for your templates. The following will return the file type for the first file in a folder chosen. Run the script and choose your Templates folder.

   set theFolder to choose folder
   tell application "Finder"
	set testType to file type of file 1 of theFolder
   end tell

Looking Forward

To make your DocFromTemplates script even more usable, you might want to have it save the document, named and date-stamped, to a pre-defined folder. This will involve a more involved user interface than just a choose from list dialog. We will look at this next time.