Scripting is the most powerful feature in InDesign—no other feature will save you as much time. You can incorporate InDesign scripts directly into your Typefi workflows by adding event scripts.
What are event scripts?
Scripting, which allows you to enhance InDesign's core capabilities, is an essential tool for creating complex documents. While you usually deploy scripts via InDesign's Scripts panel, you can also incorporate scripts directly into Typefi workflows to expand Typefi's core functionality.
All custom InDesign scripts are designed to run at a specific event, or key moment, during the automated page composition process. This article will explain the nature of these events and how to deploy event scripts in a Typefi workflow.
This introductory article provides a solid foundation for those who want to start writing scripts for Typefi workflows. In addition, this article is useful for anyone who uses Typefi Server and would like to learn more about how to deploy scripts in a Typefi workflow.
Event types
All custom InDesign scripts are designed to run at a specific event. These events can be seen on the Event scripts tab of Typefi’s Create InDesign Document and Create InDesign Book workflow actions in Typefi Server.
The Create InDesign Document workflow action has these events:
- Document start
- Section start
- Spread start
- Page start
- Spill end
- Page end
- Spread end
- Section end
- Index start
- Index end
- Document end
The Create InDesign Book workflow action has the same events as the Create InDesign Document workflow action, plus two more events:
- Book start
- Book end
The Parameters field (listed last in the Event scripts tab for both the Create InDesign document and Create InDesign book workflow actions) is not an event; instead, it's a field that you can use to pass on directives to one or more event scripts.
The events are listed in the order that they occur when a job runs through Typefi.
The spill end event can occur just once or many times when a job is run.
Event | Description | Example use cases |
---|---|---|
Book start | Used in the Create InDesign book workflow action. At book start, there is only an empty book file—no documents have been opened yet, or added to the book. Essentially, a script only has access to the book file’s properties. So if you were to stop a job immediately after book start, all you’d see on your screen is an empty book file. | Seldom used. At book start, the behaviour of the automated page composition process can be changed. For instance, in workflows that use the MathTools plug-ins, a MathML handler is installed to place MathML in the InDesign documents. Another example is a hotfix to fix a problem or add customisations. |
Document start | Typefi has opened a copy of the template and prepared it for the job: all pages after the first page are removed, the first page is cleared, and the document is saved using the name specified in the General tab of the workflow action. | A script can activate particular layers (perhaps informed by the contents of a Typefi field), set a spot colour, change paragraph styles, or set the unit of measurement to points. What a script can do here can often be done at document end too, but document start is more efficient because the document is much smaller. |
Section start | Typefi has created a new Typefi Section. Typefi Sections define divisions within a publication that break it into logical chunks and are used to specify which Adobe InDesign master pages to use during the composition process and in what order. | Rarely used. |
Spread start | A script sees the first page of the spread (the left-hand page in left-to-right workflows). | Seldom used. Instead, use page start when the page is a left-hand page in a left-to-right workflow. |
Page start | Typefi has added a new page and has overridden all master elements onto the page. If there’s a Main Story Frame on the page and a previous Main Story Frame, then the Main Story is threaded. The same goes for the table of contents (TOC) and index frames. Floating and fixed elements have not yet been placed. However, the above description does not hold for the first page of a Typefi Section. On these pages, no frames have been placed or overridden. |
Scripts can place a continuation notice for breaking tables or extend oversized text boxes. In general, run a script at page start if you want to do things to a page before Typefi starts placing floating elements on that page. |
Spill end | Typefi has read a story from the Content XML, formatted it, and placed it in a text frame. This includes any anchored frame, index markers, and any tables embedded in a story. Floating elements are separate spills. If the story is a Main Story, then it will usually be overset. Because most of the story will be overset, scripts typically can’t deal with geometry: properties such as horizontalOffset , baseline , and geometricBounds are not available for the part of the story that is overset.Scripts that change the content of a story must run either at spill end or, if they depend on page geometry, at page end. Both are effective and efficient, especially in books with a small number of stories, such as novels. If a script can be done here, do it—it’s very efficient. |
Several Typefi script modules run here; for example, conditional spacing, conditional keeps, and advanced GREP styles. |
Page end | Typefi is done with the page—all text, and all floating and fixed elements, have been placed. If there aren’t any floating elements to be placed, a page looks the same at page start and page end. | Locate the Main Story frame on the page and change its height to a percentage of its standard height |
Spread end | Coincides with page end at a right-hand page (in a left-to-right workflow). | Seldom used. Instead, use page end when the page is a left-hand page in a left-to-right workflow. |
Section end | A Typefi Section has been finished. In a book job, each Typefi Section is produced as a separate document. Typefi Sections define divisions within a publication that break it into logical chunks and are used to specify which Adobe InDesign master pages to use during the composition process and in what order. | Place a thumb tab at the edge of every page. What can be done at section end can often also be done at document end. |
Index start | Any index markers are processed at spill end. The index that you see in the Index panel in an InDesign document is built up while the document is paginated. At index start, all index markers have been processed so that the Index panel is populated. Scripts have full access to the Index panel. But the index has not yet been generated—Typefi is about to do that. |
Create a list of topics for an index, set or change the sort order of indexes, or add a page range to index entries. |
Index end | The index has been generated, placed, and paginated. | Place repeat topics in an index or apply special keep options. In general, use any scripts that need to see the finished index. |
Document end | The document is finished, including the index and the table of contents. Scripts have access to the full document. This event is comparable to opening a document in your desktop InDesign and running a script from InDesign’s Scripts panel. When run as part of a job, document end scripts must not change the page layout to avoid misaligning the table of contents or the index. If a script does change the text flow, then that script has to update the table of contents and the index. |
Place bars in the margins, add a shaded background, manipulate running headers, log various types of document diagnostics, such as missing glyphs, or detect overset text frames and table cells In general, document end scripts can add things to pages that don’t change the layout. |
Book end | Used in the Create InDesign book workflow action. All book files have been finished: the table of contents (if present) has been redone, any cross-references have been updated, and the index has been generated. The book end event is comparable to a desktop situation: open a book, open all its content, and run a script from InDesign’s Scripts panel. Like document end scripts, book end scripts must not change the layout of any documents. |
Scripts can do what most document end scripts can do. A typical book end script adds blank pages to ensure the book's extent is a multiple of 8, 16, 32, or whatever the signature's size is. In general, book end scripts can add things to pages that don’t change the layout. |
Parameters | The Parameters field is not an event script. Instead, it's a field you can pass on information to one or more event scripts. Script parameters are strings and can take any form in principle, but it’s good practice to use JavaScript Object Notation (JSON). All scripts can access parameters set in the Parameters field. More complex parameters can be handled differently; for instance, in configuration tables in the template. |
Use parameters to run a job with a certain spot colour: {'spotColour':'Red'} , or differentiate proof and print jobs: {'output':'Proof'} You can combine several pieces of information in one string, as in: {'spotColour': 'Red', output: 'Proof'}
|
Deploying event scripts in a Typefi workflow
In Typefi Server 8.4 and later, you can copy scripts to Typefi Server in the same way you copy any other file. It doesn’t matter where the scripts are.
You can create a single scripts folder, which is fine if you use just a small handful of scripts. But, if you use many scripts at different events, we recommend creating folders for each event for which you have scripts.
For example, you could create a PageEnd
folder and place all page end scripts in it and a DocumentEnd
folder for document end scripts. It’s entirely up to you.
Once the scripts are in place, specify them in the workflow action. For example, go to the Create InDesign Document action or the Create InDesign Book action. Then go to the Event scripts tab.
To select an input for an event script, click Choose File (folder icon) to browse for a file on Typefi Server (alternatively, click Browse within the Choose File dialog to browse for a file on your local computer).
For example, to add a page end script, click the folder icon, navigate to the script you uploaded, select it, and click Choose. The script’s name is inserted in the Page end field.
Scripts are run in the order in which you see them. To change the order of two or more scripts, drag them around with the mouse.
You can also add several scripts at once, and they will display alphabetically by default. For this reason, we often use two-digit prefixes for script names, so we know the order in which they should appear. For example:
20_KeepFloatInSection.jsxbin
30_BalancePages.jsxbin
The two-digit prefixes are also useful when troubleshooting. For example, if you remove a script to run some tests and then want to add it back in, it’s easy to see where it goes.
Comments
0 comments
Please sign in to leave a comment.