Search This Blog

Showing posts with label JavaScript Programmer. Show all posts
Showing posts with label JavaScript Programmer. Show all posts

How to build Scripting in Indesign?

To one degree or another, anything you can do manually in InDesign can be automated via a script. Such scripts can be written in Mac-only AppleScript, Windows-only Visual Basic Script, or cross-platform JavaScript. They can do something as simple as preload the Swatches panel with your corporate colors and they can perform highly complex, multistaged operations such as turning a blank page into a press-ready layout. Using scripts, InDesign can also be connected to other applications—for example, data from a spreadsheet or database can be sucked into InDesign and laid out automatically. The possibilities are limited only by your imagination and coding skill. Covering what can be done and how to do it is far beyond the space available in this tome. Entire books have been written on the subject, and Adobe wrote one of the best—the InDesign CS3
Scripting Guide. There are three variations of the InDesign CS3 Scripting Guide: one each for Apple- Script, Visual Basic Script, and JavaScript. You’ll find them as PDFs in the Adobe InDesign Documentation\ cripting folder on the InDesign or Creative Suite DVD. If you don’t have your DVDs on hand, you can also grab copies free of charge from www.adobe.com/go/scripting_id.
You’ll want to begin with the Adobe Intro to Scripting, progress through InDesign CS3 Scripting Tutorial, and use the JavaScript Tools Guide CS3 and the three script-language-specific versions of the InDesign CS3 Scripting Guide for reference. Accompanying the scripting tutorial and reference documents are hundreds of sample scripts that do everything from creating printer presets to unlinking text frames, placing text files to laying out events calendars. In addition to those, there are hundreds of other scripts floating around the Internet, most created by other InDesign users to address specific workflow needs. A great place to look for them is the Adobe Exchange at www.adobe.com/cfusion/exchange/. There you can find many scripts (and more!) for InDesign and every other Adobe product. I would hope you’ll find ones that function on your platform.
When you’ve written or obtained scripts you’d like to use, you have to give them to InDesign. Do that by closing InDesign and copying the scripts to the correct location for your platform: Mac OS X: Users/[username]/Library/Preferences/Adobe InDesign/Version 5.0/Scripts Windows XP: Documents and Settings\[username]\Application Data\Adobe\InDesign\ Version 5.0\Scripts Windows Vista: Users\[username]\AppData\Roaming\Adobe\InDesign\Version 5.0\Scripts When you relaunch InDesign, the scripts will be available in the User group on the Scripts panel, which can be opened by choosing Window >Automation >Scripts. Under Application in the panel, you’ll also see numerous sample scripts that are not in the locations noted above. If you want to delete these, you’ll find them in the InDesign application installation location:
Mac OS X: Applications/InDesign CS3/Scripts/Scripts Panel/Samples Windows: Program Files\Adobe InDesign CS3\Scripts\Scripts Panel\Samples To execute a script on the Scripts panel, double-click it.
Note that many scripts function only when a specific condition has been met—such as pre-selecting certain types of objects or highlighting text. Indeed, many scripts that manipulate or work from objects require that objects be named. This is where the Script Label panel comes into play. The Script Label panel (Window >Automation >Scripts) has no buttons, no flyout menu, and, apparently, nothing else. Actually, the entire panel is a single text field. Select an object on the page or pasteboard, click once inside the Script Label panel, and begin typing a name or label for the object. That’s it. That’s all it does. But, once named with the label a script expects, the object can then be manipulated by the script.
Script writers can attach scripts and scripted functions to InDesign documents and to menu commands; doing so, while incredibly powerful, represents a security risk. Consequently, Adobe shipped InDesign with the ability to run such scripts turned off. In InDesign’s preferences, on the General pane, the Enable Attached Scripts option is that control. To allow the execution of scripts attached to documents, check Enable Attached Scripts.

Find/Change Styles to the Rescue

Mr. X worked as the final stop in a publication workflow that involved nine layout artists, each working on different portions of a 320-page quarterly. His job was to collect and proof everyone’s work, stitch it all together into a single publication managed by an InDesign book, and fix any mistakes before imposing the issue and sending it to press. Ofcourse, the publication had a style guide, templates, and preconfigured paragraph and character styles; invariably, however, the articles and sections Mr. X received from the other creatives contained numerous style overrides in the form of local formatting—all of which Mr. X had to fix before the publication went to press. Making matters worse, the publication also ran per issue anywhere between 1 and 10 articles and pieces of articles from outside agencies and filler libraries. The outside contributions were formatted in ways that rarely bore any resemblance to Mr. X’s templates.
Wrangling these wild styles should have been as easy as selecting paragraphs and applying or reapplying paragraph styles. Unfortunately, doing so cleared out desired overrides, most notably italic. Consequently, Mr. X found himself spending days staring at side-by-side comparisons of original pages and pages with correct paragraph styles, locating italicized words in the former, and manually italicizing the same words in the latter. The process took so long that Mr. X had to push up the issue closing date—which, of course, some members of the team understood to mean more time between submission and press for making last-minute rewrites, leading to more formatting cleanup and often on the same story more than once.
The real solution to Mr. X’s problem lay with stricter enforcement of the publication’s style guide, which was in the offing but still left Mr. X with a lot of extra work in the interim. Although style enforcement might improve the consistency of work from Mr. X’s coworkers, policy changes for content from external agencies wasn’t likely to improve as quickly as internal policy changes. By way of retaining Mr. X’s direct control over fixing the publication, there is a two-step solution.
First, Mr. X should identify all the formatting options that fell under the heading of “desired override”— in other words, any appropriately used character-level formatting such as italic, a couple of different underline and coloring styles used for assorted kinds of URLs listed in stories, and small caps for acronyms and occasional other uses. Mr. X should create character styles to hold each of the settings—one for small caps, one each for the types of URLs, one each for italic, bold-italic. Mr. X also should create a Regular character style that specifically disallowed all the formatting options of all the other character styles; using the Regular style would instantly strip off the effects of, say, the bold-italic style, reverting the selected text to non-bold, non-italic. Mr. X should add these styles to the main template.
Step two is building and enacting a procedure to replace wanted style overrides with character styles and then remove all unwanted overrides. No sweat. Using Find/Change (Edit > Find/Change), Mr. X should search for any italic glyph and assigned it to the Italic character style. You see those settings in the screenshot of the Find/Change dialog. Similar searches were run for each of the other format overrides that had matching character styles. Each replacement criteria set was saved as a reusable query.

To revert undesirable overrides back to their correct paragraph styles, additional searches were performed, one for each paragraph style. In that case, it was even simpler: both Find Format and Change Format were set to the same paragraph style and no other options.

When InDesign performs a Find/Change with such criteria, it automatically strips off any overrides—but not those properly assigned to character styles. So, to remove any unwanted overrides on the Body Copy style, Mr. X set the Find Format to search for Paragraph Style: Body Copy; the Change Format was also set to only Paragraph Style:
Body Copy. InDesign rolled through all the stories in the document, finding every instance of text in the Body Copy style, and force reapplying the paragraph style. Mr. X’s problem was solved.

To make things even faster, and with the help of a JavaScript programmer in Mr. X’s IT department, even all the Find/Change queries were automated. Now Mr. X just executes the Style Cleanup script from the Scripts panel. Formatting cleanup that used to take his days is finished within a couple of minutes.
Blog Widget by LinkWithin