Your prescription for increased productivity and profitability
If you are a design studio that produces a variety of products (from business cards to brochures), you most likely have found ways to shortcut your workflow for creating new documents:
If you have a repeating document such as a newsletter or standing ad, having a template tucked away in a protected folder can not only save time, but assures consistency of style. The downside of working with templates can be in their not being flexible. For instance, if the size of the document, margins, or other document preferences change, you may find yourself spending the few precious minutes you may have saved updating the template.
For this blog we will explore working with document presets.
For documents prone to change, you may prefer having a collection of document presets at your disposal. However, if you have presets for web, print, and digital publishing your operators may end up with a pretty sizable list of presets to have to filter through. InDesign does not offer a way to filter through your list of document presets, but you can do this with a script. The following are some ideas.
You can filter out the document presets that have web intent. The problem is that presets having both print intent and Digital Publishing intent show up in a script as having print intent. Additionally, you cannot set intent to be DPS_INTENT as indicated in the scripting dictionaries.
If you just need to filter presets having web intent from print, you can do so with the following:
--returns list of document preset names having web intent tell application "Adobe InDesign CS6" set nameList to name of document presets whose intent is web intent end tell nameList
#target "InDesign-8.0" //returns list of document presets by name having web intent var nameArr = []; var objRef = app.documentPresets; for (var i = 0; i < objRef.length;i++){ if (objRef[i].intent==DocumentIntentOptions.WEB_INTENT) { nameArr.push(objRef[i].name); } }
Once you have a list of preset names, you could then have the user select the preset to use from the list of names:
--returns name of preset chosen from choose from list set userPrompt to "Select document preset" tell application "Adobe InDesign CS6" set nameList to name of document presets whose intent is web intent end tell if length of nameList > 2 then set nameList to rest of nameList --drops first item from the list set userChoice to choose from list nameList with prompt userPrompt if class of userChoice is not list then display alert "User cancelled" set presetName to missing value else set presetName to item 1 of userChoice end if end if
Notice in the example above the line that sets the value of nameList to rest of nameList. This drops the first item “[Default]” from the list. Were the user to choose this item, an attempt to create a document using this preset would error.
//returns name of preset chosen from custom dialog #target "InDesign-8.0" var nameArr = []; var objRef = app.documentPresets; var userPrompt = "Choose Document Preset"; for (var i = 0; i < objRef.length; i++) { if (objRef[i].intent==DocumentIntentOptions.WEB_INTENT){ nameArr.push(objRef[i].name); } } if (nameArr.length > 2) { nameArr.shift(); //removes first item from array try { var presetIndex = chooseFromList_Index ("Document Presets", true, "Choose from List", userPrompt, nameArr, 0); var presetName = nameArr[presetIndex]; }catch (e) { alert (e); } }else { alert ("No preset found"); } //returns index of item chosen from dropdown function chooseFromList_Index (dlgName, cancelIt, dlgLabel, labelText, dropList, defaultChoice) { var userCancelled = true; //make sure that user interaction levels will allow a dialog var origLevel = app.scriptPreferences.userInteractionLevel; app.scriptPreferences.userInteractionLevel = UserInteractionLevels.INTERACT_WITH_ALL; //create the dialog var dlgRef = app.dialogs.add({canCancel:cancelIt, label:labelText, name:dlgName}); //create master column with a single row var dlgMColumn = dlgRef.dialogColumns.add(); var dlgMRow = dlgMColumn.dialogRows.add(); //add a container for your items; we are providing two dialog columns: one for a label and one for the widget var dlgColumn1 = dlgMRow.dialogColumns.add(); var dlgColumn2 = dlgMRow.dialogColumns.add(); //add your items for your container (use container reference for parent dlgColumn1.staticTexts.add({staticLabel:labelText}); var choiceField = dlgColumn2.dropdowns.add({stringList:dropList, selectedIndex:defaultChoice, minWidth:144}); //show the dialog and capture the result if (dlgRef.show() == true) { userCancelled = false; var userChoice = choiceField.selectedIndex; } dlgRef.destroy();//destroy dialog window //restore script preference app.scriptPreferences.userInteractionLevel = origLevel; if (userCancelled == true) { throw ("User cancelled"); } return userChoice; }
This option requires that you set up a naming convention for your document presets. For instance, all presets for Digital Publishing Suite could start with “DPS_”, and so on.
--Filter list of document presets using begins with set nameList to {} tell application "Adobe InDesign CS6" try --if no presets are found as designated, an error will be thrown set nameList to name of document presets whose name begins with "DPS_" end try end tell nameList
//Filter list of document presets using first characters of each preset #target "InDesign-8.0" var nameArr = []; var objRef = app.documentPresets; var userPrompt = "Choose Document Preset"; for (var i = 0; i < objRef.length; i++){ if (objRef[i].name.substr(0,4)=="DPS_"){ nameArr.push(objRef[i].name); } } if (nameArr.length > 0) { try { var presetIndex = chooseFromList_Index ("Document Presets", true, "Choose from List", userPrompt, nameArr, 0); var presetName = nameArr[presetIndex]; } catch (e) { alert (e); } } else { alert ("No preset found"); } presetName
tell application "Adobe InDesign CS6" try --if no presets are found as designated, an error will be thrown set nameList to name of document presets whose intent is web intent and name begins with "iPad" end try end tell --continue as above
Change the if statement in the example above to read as follows:
if (objRef[i].intent == DocumentIntentOptions.WEB_INTENT && objRef[i].name.substr(0,4) == "iPad") { nameArr.push(objRef[i].name); }
For the most part, documents created using a document preset should consistently have the same options. The one exception to this rule might be the number of pages. For this reason, I set my non-facing page presets to have 1 page; facing page presets with 4. Then, I give the user the option for setting the number of pages as part of the custom dialog. The following AppleScript uses a custom dialog for choose from list with the number of pages option added.
set userPrompt to "Choose Document Preset" tell application "Adobe InDesign CS6" try set nameList to name of document presets whose intent is web intent and name begins with "iPad" set userResponse to my chooseFromList_Index("Presets", true, "Choose From List", userPrompt, nameList, 1) set presetIndex to item 1 of userResponse set presetName to item presetIndex of nameList set numberPages to item 2 of userResponse on error (errMsg) display alert errMsg end try end tell presetName (*returns index of user's choice from dropdown and edit value from editbox*) on chooseFromList_Index(dlgName, cancelIt, dlgLabel, labelText, dropList, defaultChoice) set userCancelled to true tell application "Adobe InDesign CS6" set origLevel to user interaction level of script preferences set user interaction level of script preferences to interact with all set dlgRef to make dialog with properties {canCancel:cancelIt, label:labelText, name:dlgName} tell dlgRef tell (make dialog column) set dlgMRow to make dialog row tell dlgMRow set dlgColumn1 to make dialog column set dlgColumn2 to make dialog column end tell tell dlgColumn1 make static text with properties {static label:labelText} make static text with properties {static label:"Number Pages"} end tell tell dlgColumn2 set presetField to make dropdown with properties {string list:dropList, selected index:defaultChoice} set pageField to make integer editbox with properties {edit value:1, min width:72, minimum value:1, maximum value:100} end tell end tell end tell set userResponse to show dlgRef if userResponse is true then set userCancelled to false set presetChoice to (selected index of presetField) + 1 set numberPages to edit value of pageField end if destroy dlgRef set user interaction level of script preferences to origLevel if userCancelled then error "User Cancelled" return {presetChoice, numberPages} end tell end chooseFromList_Index