use to select files and folders, specify export or printing options, or otherwise
customize ... AutomatorTutorialAppleScript/Introduction/chapter_1_section_1.
html).
BUILDING AN ADOBE INDESIGN CS3 WORKFLOW IN AUTOMATOR
Building and Adobe® InDesign® CS3 Workflow in Automator © 2007 Adobe Systems Incorporated. All rights reserved.
Adobe, the Adobe logo, and InDesign are either registered trademarks or trademarks of Adobe Systems Incorporated in the United States and/or other countries. Apple and Mac OS are trademarks of Apple Computer, Inc., registered in the United States and other countries. All other trademarks are the property of their respective owners. The information in this document is furnished for informational use only, is subject to change without notice, and should not be construed as a commitment by Adobe Systems Incorporated. Adobe Systems Incorporated assumes no responsibility or liability for any errors or inaccuracies that may appear in this document. The software described in this document is furnished under license and may only be used or copied in accordance with the terms of such license. Adobe Systems Incorporated, 345 Park Avenue, San Jose, California 95110, USA.
Building an Adobe InDesign CS3 Workflow in Automator Automator is an Apple® application for Mac OS® X that can automate repetitive procedures. Automator and InDesign scripting can work very well together. Automator uses actions to create workflows. An action performs a step in a task, like opening a file, importing a graphic, formatting text, or exporting to PDF. A workflow comprises several actions performed in sequence. Automator actions typically contain user-interface elements that you (or other users of your action) can use to select files and folders, specify export or printing options, or otherwise customize the behavior of the action. Part of the process of creating any action is to design the user interface. This tutorial shows you how to do the following: ●
Design an Automator workflow for InDesign.
●
Build five Automator actions.
●
Connect the actions into a workflow.
As we work through the process of creating each Automator action, we cover these topics: ●
Creating the user interface.
●
Editing .plist files.
●
Adding AppleScript.
●
Building and debugging.
Note: This document assumes you have a basic working knowledge of XCode, AppleScript, and InDesign scripting.
Getting Started with Automator A good place to start learning about Automator is Introduction to Automator AppleScript Actions Tutorial (http://developer.apple.com/documentation/AppleApplications/Conceptual/ AutomatorTutorialAppleScript/Introduction/chapter_1_section_1.html). This provides a basic tutorial on the process of creating an Automator action. Once you complete the tutorial, you can move on to Introduction to Automator Programming Guide (http://developer.apple.com/documentation/AppleApplications/Conceptual/AutomatorConcepts/ index.html). This document goes into much greater technical detail. Another useful document is Automator Action Property Reference (http://developer.apple.com/ documentation/AppleApplications/Conceptual/AutomatorConcepts/Articles/AutomatorPropRef.html). This presents details about the XML elements in .plist file.
3
Building an Adobe InDesign CS3 Workflow in Automator
Designing a Workflow
4
Designing a Workflow When you start creating an Automator workflow, there are several important concepts to consider. Automator is not appropriate for all workflows; some processes are not suited to the Automator environment. For example, any process that acts on the selected items on an InDesign page would be better as an InDesign script you can run from the Scripts palette. A process that involves working on multiple InDesign files in the Finder, by contrast, is a good candidate for Automator automation. Once you select an appropriate workflow, keep in mind these design considerations as you create each action: ●
What input does the action need? An action can accept two parameters, input and parameters. The input variable generally is the output from the previous action in the workflow. The input can be defined as an AppleScript list of objects, but in general it is a good idea to limit the data passed from one action to the next, to limit the dependency of one action on a previous action. The parameters parameter is the way to pass user input from the user interface to the action. Some controls are connected via bindings and some are connected via an “update parameters” handler— both of which we will demonstrate in the sample actions.
●
What will happen as the action executes? The majority of the work of an action should take place within the run routine or in handlers called from it.
●
What output will result? The less that is passed from one action to the next, the less one action needs to depend on another. In general, what is passed on to the next action is a reference to the document or set of documents. Actions with fewer dependencies are much easier to re-use in other workflows.
●
What are the dependencies? Try to limit the number of external dependencies used in an action. For example, you might be tempted to include references to specific InDesign templates, graphics files, or folders. The trouble with this approach is that you will need to rebuild your action whenever you move from one computer to another, change folder names, or change filenames. Instead, set up the user interface of your action to ask for whatever initial information the action needs.
●
Try to keep each action small and simple. Ideally, each action should be one simple task. For more complex automation, assemble actions into workflows. This makes troubleshooting much easier and helps ensure your actions can be re-used in many workflows.
Overview of the Sample Actions In the sections that follow, we create a complete Automator workflow by defining a set of actions. The workflow does the following: ●
Creates a new InDesign document.
●
Populates the document with the contents of a folder.
●
Saves the document.
●
Exports the document to PDF.
●
Closes the document.
Building an Adobe InDesign CS3 Workflow in Automator
Your First InDesign Automator Action 5
The basic design ideas for each action are as follows: Action:
New Document
Place Files
Save File
Export PDF
Close Document
Input:
None.
A document.
A document.
A document.
A document.
Action — selection:
—
—
During start-up, populate a pop-up menu with PDF Export options.
—
User input:
The name of a document preset.
The location of a folder.
The location and name of a file in which to save the document.
A PDF export — preset and the location and name of a file in which to save the PDF.
Run:
Create a new document using the selected document preset.
Place the files in the folder at the end of the document. If the file being placed is a text file, autoflow the text.
Save the document to the user specified location and filename.
Save file to PDF using the selected PDF export preset and file path.
Output:
The document.
The document.
The document. The document.
Close the document.
Nothing.
Your First InDesign Automator Action Now that we have some idea of what we want to make, we can create the Close Document action for our sample workflow. This action is very simple: it has no user interface and does nothing more than close the active InDesign document without saving. Although this is the last action in our workflow, we start with it because it is the simplest.
Create the XCode Project To create the XCode project we’ll use to build the action, follow these steps: 1. Open XCode 2.2 or later. 2. Choose File > New Project:
Building an Adobe InDesign CS3 Workflow in Automator
Your First InDesign Automator Action 6
3. Choose AppleScript Automator Action:
4. Enter a name the project. The name you enter will be the actual name of the action:
Building an Adobe InDesign CS3 Workflow in Automator
Your First InDesign Automator Action 7
XCode opens a new project:
Create the User Interface in Interface Builder Next, we need to build a user interface for the action. Even though this action does not require a user interface, we must complete this step. Follow these steps: 1. Open (double-click) main.nib. XCode opens the Interface Builder (if it is not already open). 2. Double-click the View icon, to display the View window (if it is not already open). 3. Change the default text to “No User Interface” (or delete it):
Building an Adobe InDesign CS3 Workflow in Automator
Your First InDesign Automator Action 8
4. Save and close main.nib.
Edit the Info.plist File Next, we make changes to the Info.plist file: 1. In XCode, double-click Info.plist to open it. 2. Make the following changes to the text in the file. (Most of the changes simply remove the placeholder strings.) AMApplication Adobe InDesign CS3 AMCategory Adobe InDesign CS3
Building an Adobe InDesign CS3 Workflow in Automator
Your First InDesign Automator Action 9
AMDescription AMDAlert AMDInput AMDNote AMDOptions AMDRelatedActions AMDRequires AMDResult AMDSummary Closes an InDesign document without saving. AMIconName InDesignAction.tiff
The first XML element, AMApplication, associates the action with the appropriate application in the Library list in Automator. The second XML element, AMCategory, is needed when you have many actions associated with a particular application. For this set of actions, we chose to make the category the same as the application. The next XML element AMDescription, is followed by dict, a dictionary of elements used to describe the key features of the action. It is important to note that these elements also are listed in the InfoPlist.strings file, which we is discussed in the next section. The strings you use in both locations must match, or the descriptions shown in Automator does not display correctly. The last XML element we change is the string following AMIconName. This is used to identify the file that provides the icon used by Automator to display the action. We include a file in each sample project with the name InDesignAction.tiff. As long as the icon is a TIFF file and the name is the same (capitalization counts), it displays correctly in Automator. 3. Save and close Info.plist.
Edit the InfoPlist.strings File Next, we make some changes to the InfoPlist.strings file: 1. In XCode, open InfoPlist.strings and make the following changes. (Most of the changes simply remove the placeholder strings.) /* AMDescription localized strings */ AMDAlert = ""; AMDInput = ""; AMDNote = ""; AMDOptions = ""; AMDResult = "None."; AMDRequires = ""; AMDSummary = "Closes an InDesign document without saving.";
2. Save and close InfoPlist.strings.
Building an Adobe InDesign CS3 Workflow in Automator
Your First InDesign Automator Action
10
Add AppleScript to the Action Next, we add the AppleScript that makes the action work: 1. Open main.applescript and enter the following: on run {input, parameters} tell application "Adobe InDesign CS3" close document 1 saving no end tell end run
2. Save main.applescript. The AppleScript used in this action is very simple. There is only one routine, called when you click the Run button in Automator. For this action, the input and parameters parameters are ignored.
Build the Action Once you enter and save the AppleScript, you can test the action. Follow these steps: 1. From the Build and Go pop-up menu in XCode, choose Build and Run, to automatically launch Automator and load the action:
Note: In some versions of XCode, you might receive the warning: “CFBundleExecutable key is pointless with no executable.” This can be ignored.
Building an Adobe InDesign CS3 Workflow in Automator
Your First InDesign Automator Action
11
2. In Automator, select InDesign CS3, then drag the action to the area labeled “Drag or add actions here to build your workflow”:
3. If no document is open in InDesign, switch to InDesign and create a new document. 4. In Automator, click the Run button. If the action is working properly, InDesign closes the open document. At this point, any errors in the action can be dealt with using the debugging features of XCode (as described in the Apple documentation). When all debugging is complete, build the Release version of the action. (By default, XCode builds the Debug version.) Once you finish debugging and have created the Release version of the action, you can make it a permanent part of your Automator library. To do this, move the action from the XCode project build folder to the Automator library folder. The XCode project build file you need is located in: ~/XCodeProjects/Release/action
Where ~ (tilde) is your system volume and action is the name of the action. Move the action to: ~/Users/user_name/Library/Automator/
Where ~ is your system volume and user_name is your user name. You have completed one of the five actions described in this tutorial.
Building an Adobe InDesign CS3 Workflow in Automator
Creating the New Document Action
12
Creating the New Document Action Go through the steps to create the a new AppleScript action project in XCode, as described in “Create the XCode Project” on page 5. Give the new project an appropriate name, and save it. We call this action New Document. It is the first action in our sample Automator workflow.
Create the User Interface Once you create the project, you can create a user interface for the action. For this action, we need to provide a way for the user to choose a document preset before creating the new document. We do this by adding a pop-up menu to the user interface. Once we do that, we can have an AppleScript handler in the action get a list of InDesign’s document presets and display them on the pop-up menu. In general, the process of adding a user interface to an action follows these steps: ●
Add user-interface elements to the action using the Interface Builder.
●
Create keys that correspond to both user-interface elements and the parameters you want to pass to the on run handler in the action’s AppleScript.
●
Establish bindings between the user-interface elements and the keys.
To create the user interface for the New Document action, follow these steps: 1. Open main.nib (if it is not already open). 2. Double-click the View icon, to open the View window. 3. Double-click the placeholder text “(* UI elements go here. *)” and type “Document Preset: “.
4. Add a pop-up menu to the right of the text:
5. Click the Outline View button at the side of the main.nib window. Select the last two NSMenuItem entries (under NSPopUpButton > NSMenu) and press Delete. This removes the last two menu items on the pop-up menu (“Item2” and “Item3”).
Building an Adobe InDesign CS3 Workflow in Automator
Creating the New Document Action
13
Note: As you work in the Outline View, you will notice warning icons to the left of the control name (as shown in the above figures). You can ignore these warnings.
Add a Parameter Next, we add a parameter that is passed to the on run handler in the AppleScript stored in the action. Follow these steps: 1. Click the Icon View button at the side of the main.nib window, then select the Parameters icon. 2. In the Inspector palette, choose Attributes. Click the Add button at the bottom of the palette, to add a key. Double-click the placeholder text (newKey), and enter the same name you entered in Step 3 in “Create the User Interface” on page 12, DocumentPreset.
Building an Adobe InDesign CS3 Workflow in Automator
Creating the New Document Action
14
Connect the Key to the User Interface Next, we connect the pop-up menu to the parameter: 1. Select the pop-up menu and press Command-Shift-I to display the Inspector palette. 2. From the palette pop-up menu, choose AppleScript, to display the AppleScript properties of the menu. 3. In the Name field, enter DocumentPreset. In the Event Handlers section, check the “awake from nib” option.
4. From the pop-up menu in the Inspector palette, select Bindings. 5. In the list shown in the Inspector palette, select selectedValue, then turn on the Bind option. From the Model Key Path pop-up menu, choose DocumentPreset.
6. Save and close main.nib.
Building an Adobe InDesign CS3 Workflow in Automator
Creating the New Document Action
15
Edit the Info.plist file Next, make the necessary changes to the Info.plist and InfoPlist.strings files. The changes are very similar to those made in the first sample, with one addition. Follow these steps: 1. In XCode, open Info.plist and make the following changes: AMApplication Adobe InDesign CS3 AMCategory Adobe InDesign CS3 AMDefaultParameters DocumentPreset AMDescription AMDAlert AMDInput InDesign document object reference. AMDNote AMDOptions AMDRelatedActions AMDRequires AMDResult InDesign document object reference. AMDSummary Creates a new InDesign document using the specified document preset. AMIconName InDesignAction.tiff
Note: The AMDefaultParameters XML element tells the action which parameters will be passed to the AppleScript in the action. To do this, you create a new XML element (), which contains two XML elements ( and ) for each parameter. The content of the element must match the value we entered for the parameter, spelled and capitalized exactly as you entered it in the Inspector.
Building an Adobe InDesign CS3 Workflow in Automator
Creating the New Document Action
16
2. Edit the InfoPlist.strings file: /* AMDescription localized strings */ AMDAlert = ""; AMDInput = ""; AMDNote = ""; AMDOptions = ""; AMDResult = "InDesign document object reference."; AMDRequires = ""; AMDSummary = "Creates a new InDesign document using the specified document preset.";
3. Save InfoPlist.strings.
Add AppleScript to the Action Next, we add an AppleScript to the action. Unlike the AppleScript shown in the first action, this script uses the parameters passed from Automator. 1. Open main.applescript, and enter the following AppleScript: on run {input, parameters} set myDocumentPreset to (|DocumentPreset| of parameters) tell application "Adobe InDesign CS3” if myDocumentPreset is not equal to "" then set myPreset to document preset myDocumentPreset else set myPreset to document preset 1 end if set myDocument to make document with properties {document preset:myPreset} end tell return myDocument end run on awake from nib theObject set theObjectName to "" try set theObjectName to name of theObject if theObjectName = "DocumentPreset"then my myPopulatePopUp(theObject) end if end try end awake from nib on myPopulatePopUp(myPopupMenu) tell application "Adobe InDesign CS3” set myDocumentPresets to name of every document preset end tell set title of menu item 1 of menu of myPopupMenu to (item 1 of myDocumentPresets) repeat with myCounter from 2 to (count myDocumentPresets) tell menu of myPopupMenu make new menu item at end with properties {title:item myCounter of myDocumentPresets} end tell end repeat end myPopulatePopUp
2. Save main.applescript.
Building an Adobe InDesign CS3 Workflow in Automator
Creating the Place Files Action
17
Build, Debug, and Deploy Build, debug, and deploy the action, as described in “Build the Action” on page 10.
Creating the Place Files Action Go through the steps to create the a new AppleScript action project in XCode, as described in “Create the XCode Project” on page 5. Give the new project an appropriate name, and save it. We call this action Place Files. It is the second action in our sample Automator workflow. If you completed Introduction to Automator AppleScript Actions Tutorial (http://developer.apple.com/ documentation/AppleApplications/Conceptual/AutomatorTutorialAppleScript/Introduction/ chapter_1_section_1.html), skip to the next procedure. If you did not complete the tutorial, you need to add the Automator palette to the Interface Builder. To add the palette, follow these steps: 1. Open the Interface Builder (you can double-click main.nib in your project to do this). 2. Choose Interface Builder > Preferences. 3. Click the Palettes button to display a list of the currently loaded palettes. 4. Click the Add button. Interface Builder displays a file browser. 5. Navigate to ~/Developer/Extras/Palettes (where ~ is your system volume) and select the AMPalette.palette file. Click Open. Interface Builder adds the palette. You should see an Automator icon, as shown below.
Create the User Interface After installing the Automator palette in the Interface Builder, follow these steps: 1. Open main.nib (if it is not already open). 2. Click the Automator icon. 3. Drag the Directory Chooser pop-up menu onto the View window. (This control also is known as AMPathPopUpButton.) 4. With the Directory Chooser pop-up menu selected, choose Tools > Show Inspector, to display the Inspector for the control.
Building an Adobe InDesign CS3 Workflow in Automator
Creating the Place Files Action
18
5. Turn on the Choose Panel As Sheet option, as shown below:
6. Save and close main.nib.
Add a Parameter Next, we connect the pop-up menu to the parameters that will be passed to the on run handler in the AppleScript in the action. The process is very similar to that shown in “Add a Parameter” on page 13. 1. In the Instances pane of the main.nib window, select the Parameters object. (Double-click main.nib to display the window, if it is not already visible.) 2. Choose Tools > Show Inspector to display the Inspector palette (if it is not already visible). 3. The Attributes panel of the Inspector palette displays the parameters’ (NSObjectController) attributes that will be displayed. 4. Click the Add button to add a parameter.
Building an Adobe InDesign CS3 Workflow in Automator
Creating the Place Files Action
19
5. Double-click newKey, and enter a name for the parameter. We used DirectoryOfFiles.
Connect the Key to the User Interface With the key defined, you can now connect the user-interface element (pop-up menu) to the key. To accomplish this, follow these steps (which are very similar to the procedure shown in “Connect the Key to the User Interface” on page 14): 1. Double-click the View icon in the main.nib window, to show the View window (if it not already visible). 2. In the View window, select the Directory Chooser pop-up menu. 3. From the pop-up menu at the top of the Inspector palette, select Bindings. 4. From the Bind To pop-up menu, choose Parameters (NSObjectControls). 5. Click the triangle next to Path, to display the path options. 6. In the Controller Key field, type selection.
Building an Adobe InDesign CS3 Workflow in Automator
Creating the Place Files Action
7. From the Model Key Path pop-up menu., choose DirectoryOfFiles:
8. Save and close main.nib.
Edit the Info.plist and InfoPlist.strings Files Next, make the necessary changes to the Info.plist and InfoPlist.strings files. The changes are very similar to those made in the first sample, with one addition. 1. In XCode, open Info.plist and make the following changes: AMApplication Adobe InDesign CS3 AMCategory Adobe InDesign CS3 AMDefaultParameters directoryOfFiles
20
Building an Adobe InDesign CS3 Workflow in Automator
Creating the Place Files Action
21
AMDescription AMDAlert Some Place operations (e.g., placing an Excel file) can display an Import Options dialog box. AMDInput InDesign document object reference AMDNote AMDOptions AMDRelatedActions AMDRequires AMDResult InDesign document object reference AMDSummary Places files at the end of the current InDesign document. AMIconName InDesignAction.tiff
2. Save and close Info.plist. 3. Edit the InfoPlist.strings file.: /* AMDescription localized strings */ AMDAlert = "Some Place operations (e.g., placing an Excel file) can display an Import Options dialog box."; AMDInput = "InDesign document object reference"; AMDNote = ""; AMDOptions = ""; AMDResult = "InDesign document object reference"; AMDRequires = ""; AMDSummary = "Places files at the end of the current Adobe InDesign CS3 document.";
4. Save and close InfoPlist.strings.
Building an Adobe InDesign CS3 Workflow in Automator
Creating the Place Files Action
22
Add AppleScript to the Action Next, add an AppleScript to the action. Unlike the AppleScript shown in the first sample action, this script uses the parameters passed from Automator. Follow these steps: 1. Open main.applescript and enter the following AppleScript: on run {input, parameters} --Get the document reference from the input. set myDocument to input set myFilesToPlace to (|DirectoryOfFiles| of parameters) if myFilesToPlace is not "" then try --The path is provided in POSIX format, and we need it --as an AppleScript alias, so convert the path: set myTargetFolder to call method "stringByExpandingTildeInPath" of myFilesToPlace set myTargetFolder to (POSIX file myTargetFolder) set myTargetFolder to myTargetFolder as alias on error error number -43 from myTargetFolder end try else set myTargetFolder to path to desktop end if --Get a list of the file names in the target folder. set myFiles to list folder myTargetFolder without invisibles repeat with myCounter from 1 to (count myFiles) --Build an alias from the folder path and file name. set myFile to ((myTargetFolder as string) & (item myCounter of myFiles as string)) as alias set myFileInfo to info for myFile if (folder of myFileInfo is false) then tell application "Adobe InDesign CS3” tell myDocument set myLastPage to page -1 if (count page items of myLastPage) is not 0 then set myLastPage to make page at end end if tell myLastPage tell margin preferences set myX to left set myY to top end tell place myFile place point {myX, myY} end tell end tell end tell end if end repeat return myDocument end run
2. Save main.applescript.
Building an Adobe InDesign CS3 Workflow in Automator
Creating the Save File Action
23
Note: In the above AppleScript, you might have noticed the following line: call method "stringByExpandingTildeInPath" of myFile
This line calls an Objective-C method in the NSString class to convert the tilde (~) character in the file path. Once the character is converted, you can use standard AppleScript routines to convert from the POSIX format to a file alias.
Build, Debug, and Deploy Build, debug, and deploy the action as described in “Build the Action” on page 10.
Creating the Save File Action We have completed three sample actions. Next, we build an action that saves an InDesign document to a specific filename and folder. Create a new AppleScript Action project in XCode, as described in “Create the XCode Project” on page 5. Give the new project an appropriate name, and save it. We call this action Save File.
Create the User Interface As in the previous examples, we use the Interface Builder to add a series of user controls to the action. Follow these steps: 1. Open main.nib. 2. Add two static text fields, a Directory Choose pop-up menu (as shown in “Create the User Interface” on page 12), and an editable text field, so the action View looks like this:
3. Select the editable text field and choose Show Inspector from the Tools menu (if the Inspector palette is not already visible).
Building an Adobe InDesign CS3 Workflow in Automator
Creating the Save File Action
24
4. From the Size pop-up menu, choose Small:
5. From the Inspector palette pop-up menu, select AppleScript. 6. In the Name field, enter the name of the object. We used the name NewFileName. 7. In the Editing area of the Event Handlers list, enable the End Editing option. When you select this option, Interface Builder automatically adds an empty event handler to main.applescript. You will use this routine to store the name of the file the user selects.
8. In the main.nib window, double-click the View icon (or deselect the text edit field), then enter a new name in the Name field (we used TheView).
Building an Adobe InDesign CS3 Workflow in Automator
Creating the Save File Action
25
9. In the Automator action View area of the Event Handlers list, turn on the Update Parameters option:
10. In the main.nib window, select the Parameters object, then choose Attributes from the Inspector palette pop-up menu. Add two parameters (as shown in “Add a Parameter” on page 13). The first parameter is the NewFileName key, which is used by the pop-up menu. The second is the SaveDocumentHere key, which is used to send the value of the edit text field to the on run handler in main.applescript.
11. Save and close main.nib.
Building an Adobe InDesign CS3 Workflow in Automator
Creating the Save File Action
26
Edit Info.plist and InfoPlist.strings Next, edit the Info.plist and InfoPlist.strings files. 1. In XCode, open the Info.plist file and make the following changes: AMApplication Adobe InDesign CS3 AMCategory Adobe InDesign CS3 AMDefaultParameters PlaceDocHere NewFileName AMDescription AMDAlert AMDInput InDesign document object reference AMDNote AMDOptions AMDRelatedActions AMDRequires AMDResult InDesign document object reference AMDSummary Saves the InDesign Document to the user selected location. AMIconName InDesignAction.tiff
2. Save and close Info.plist. 3. Open the InfoPlist.strings file and make the following changes: /* AMDescription localized strings */ AMDAlert = ""; AMDInput = "InDesign document object reference"; AMDNote = ""; AMDOptions = ""; AMDResult = "InDesign document object reference"; AMDRequires = ""; AMDSummary = "Saves an InDesign document to a specified location.";
4. Save and close InfoPlist.strings.
Building an Adobe InDesign CS3 Workflow in Automator
Creating the Export PDF Action
27
Add AppleScript to the Action Next, add the AppleScript that makes the action work: 1. Select main.applescript and make the code look like the following: property NewFileName : missing value on run {input, parameters} --Get the Document Reference from the input parameter set myDocument to input set myFileName to (|NewFileName| of parameters) set mySaveLocation to (|SaveDocumentHere| of parameters) if mySaveLocation is not "" then try --The path is provided in POSIX format, so convert it to an Alias. set myFolder to call method "stringByExpandingTildeInPath" of saveLocation set myFolder to (POSIX file myFolder) set myFolder to myFolder as alias on error error number -43 from the myFolder end try else set myFolder to path to desktop end if if myFileName is "" then set myFileName to "test file” end if tell application "Adobe InDesign CS3” set myDocument to save myDocument to ((myFolder as string) & myFileName) end tell return myDocument end run on update parameters theObject parameters theParameters set |NewFileName| of theParameters to NewFileName return theParameters end update parameters on end editing theObject --Whenever the edit field changes, update the global property NewFileName. set NewFileName to string value of theObject end end editing
2. Save and close main.applescript.
Build, Debug, and Deploy Build, debug, and deploy the action as described in “Build the Action” on page 10.
Creating the Export PDF Action Create a new AppleScript action project in XCode, as described in “Create the XCode Project” on page 5. Give the new project an appropriate name, and save it. We call this action Export PDF.
Building an Adobe InDesign CS3 Workflow in Automator
Creating the Export PDF Action
28
Create the User Interface Next, we build a user interface that provides a way to select an InDesign PDF export preset and enter a filename and folder to which to save the PDF file. Follow these steps: 1. Open main.nib. 2. Create three static text fields, one Directory Chooser pop-up menu (as shown in “Create the User Interface” on page 23), and one editable text field. 3. Add a new pop-up menu to the user interface. This pop-up menu will give you a way choose which PDF export preset to use when exporting the PDF. When you run the action in Automator, the AppleScript in the action will populate the pop-up menu with the names of the currently available PDF export presets. The process of adding this pop-up menu is very similar to the steps shown in “Creating the New Document Action” on page 12.
4. Remove the second and third menu items from the pop-up menu, as shown in Step 5 of “Create the User Interface” on page 12. 5. At the side of the main.nib window, click the Icon View button, then select the Parameters icon. 6. In the Inspector palette, choose Attributes, then click the Add button at the bottom of the palette to add a key. Double-click the placeholder text (newKey) and enter the same name as you entered previously.
7. Select the pop-up menu and press Command-Shift-I to display the Inspector palette. From the palette pop-up menu, choose AppleScript to display the AppleScript properties of the menu.
Building an Adobe InDesign CS3 Workflow in Automator
Creating the Export PDF Action
29
8. In the Name field, enter PDFExportPreset. In the Event Handlers section, check the “awake from nib” option.
9. From the pop-up menu in the Inspector palette, select Bindings. 10. In the list shown in the Inspector palette, select selectedValue, then turn on the Bind option. From the Model Key Path pop-up menu, choose PDFExportPreset. There is no need to change any of the other default settings.
Building an Adobe InDesign CS3 Workflow in Automator
Creating the Export PDF Action
30
11. Click in an empty area of the View window, then choose AppleScript from the Inspector palette pop-up menu. In the Name field, enter a name for the View window. In the Automator action View section of the Event Handlers list., turn on the “update parameters” option.
12. Save and close main.nib.
Edit Info.plist and InfoPlist.strings 1. In XCode, open Info.plist and make the following changes: AMApplication Adobe InDesign CS3 AMCategory Adobe InDesign CS2 AMDefaultParameters PDFExportPreset PDFSaveFolder PDFFileName
Building an Adobe InDesign CS3 Workflow in Automator
Creating the Export PDF Action
31
AMDescription AMDAlert AMDInput InDesign document object reference. AMDNote AMDOptions AMDRelatedActions AMDRequires AMDResult InDesign document object reference. AMDSummary Exports an InDesign document as PDF to a specfied file and folder using the selected PDF export preste. AMIconName InDesignAction.tiff
2. Save and close Info.plist. 3. Open InfoPlist.strings and make the following changes: /* AMDescription localized strings */ AMDAlert = ""; AMDInput = "InDesign document object reference."; AMDNote = ""; AMDOptions = ""; AMDResult = "InDesign document object reference."; AMDRequires = ""; AMDSummary = "Exports an InDesign document as PDF to a specfied file and folder using the selected PDF export preset.";
4. Save and close InfoPlist.strings.
Building an Adobe InDesign CS3 Workflow in Automator
Creating the Export PDF Action
32
Add AppleScript to the Action 1. Select main.applescript, and enter the following AppleScript: property PDFFileName : missing value on run {input, parameters} set myDocument to input set myPDFExportPreset to (|PDFExportPreset| of parameters) set myFileName to (|PDFFileName| of parameters) if myFileName is "" or myFileName is missing value then set myFileName to "test file.pdf” end if set myFolder to (|PDFSaveFolder| of parameters) if myFolder is not "" then try set myFolder to call method "stringByExpandingTildeInPath" of myFolder set myFolder to myFolder as alias on error set myFolder to path to desktop end try else set myFolder to path to desktop end if tell application "Adobe InDesign CS3” --If no PDF export preset was selected, use the first PDF export preset. if myPDFExportPreset is not equal to "" then set myPreset to PDF export preset myPDFExportPreset else set myPreset to PDF export preset 1 end if --Construct the file path. set myFilePath to ((myFolder as string) & myFileName) export myDocument format PDF type to myFilePath using myPreset without showing options end tell return myDocument end run on awake from nib theObject set theObjectName to "" try set theObjectName to name of theObject if theObjectName = "PDFExportPreset"then my myPopulatePopUp(theObject) set |PDFExportPreset| of the parameters to title of current menu item of theObject display dialog title of current menu item of theObject end if end try end awake from nib on update parameters theObject parameters theParameters set |PDFFileName| of theParameters to PDFFileName return theParameters end update parameters on end editing theObject set PDFFileName to string value of theObject end end editing
Building an Adobe InDesign CS3 Workflow in Automator
Creating the Complete Workflow in Automator
33
on myPopulatePopUp(popupRef) tell application "Adobe InDesign CS3” set myPDFPresetNames to name of every PDF export preset end tell set title of menu item 1 of menu of popupRef to (item 1 of myPDFPresetNames) repeat with myCounter from 2 to (count myPDFPresetNames) tell menu of popupRef make new menu item at end with properties {title:item myCounter of myPDFPresetNames} end tell end repeat end myPopulatePopUp
Build, Debug, and Deploy Build, debug, and deploy the action, as described in “Build the Action” on page 10.
Creating the Complete Workflow in Automator Now that we built and tested our sample actions, we can create a complete workflow in Automator. Follow these steps: 1. Open Automator. 2. Select Adobe InDesign CS3. 3. Drag the actions into the workflow in the following sequence: ●
New Document
●
Place Files
●
Save File
●
Export PDF
●
Close Document
Building an Adobe InDesign CS3 Workflow in Automator
Creating the Complete Workflow in Automator
As you add each action, you can set up the user-interface options as you want them, or turn on the Show Action When Run option to display the action’s user interface as the action executes.
4. Save the workflow.
34