Your prescription for increased productivity and profitability
In our previous post, the discussion centered around using find/change for text. Here we will use scripts to find and change objects such as graphic lines, graphic frames, and text frames.
For example, a script can find all graphic lines that have a stroke weight of .5 and change the width of the stroke to 1 pt. Or perhaps you need to change all graphic lines colored registration to black or from black to registration. The script would be similar to what we did with text only here we will work with find object preferences and change object preferences:
tell application "Adobe InDesign CC 2015" --clear find and change preferences set find object preferences to nothing --establish properties for find objects set stroke weight of find object preferences to 0.5 --establish properties for change set stroke weight of change object preferences to 1.0 tell document 1 set foundSet to find object if foundSet is not {} then set userMsg to "There were " & length of foundSet & " instances found and changed" change object else set userMsg to "No objects found as defined for find object" end if end tell set find object preferences to nothing set change object preferences to nothing end tell activate display alert userMsg
To change a property such as the stroke color, you need change only the stroke color property for find object preferences and the change object preferences in the script above:
--establish properties for find object preferences set stroke color of find object preferences to "Black" --establish properties for change object preferences set stroke color of change object preferences to "Registration"
All find/change processes are not as straight-forward as the examples above. For example, for effects such as drop shadow a script needs to work with a child object of either transparency settings, fill transparency settings, stroke transparency settings, or content transparency settings. To understand this concept, create a document with a page item (rectangle or text frame). Manually give the object a drop shadow (Object > Effects > Drop Shadow). With the object selected, run the following test script:
tell application "Adobe InDesign CC 2015" set selList to selection set selItem to item 1 of selList tell fill transparency settings of selItem set testIt to properties end tell end tell testIt
Among the properties record returned you will find a listing similar to:
drop shadow settings:drop shadow settings of fill transparency settings of rectangle id 245 of spread id 219 of document id 1 of application "Adobe InDesign CC 2015"
Now change the test script above to read
tell application "Adobe InDesign CC 2015" set selList to selection set selItem to item 1 of selList tell fill transparency settings of selItem tell drop shadow settings set testIt to properties end tell end tell end tell testIt
With the same rectangle selected, run the script and view the result. You will see that a drop shadow has properties including size, noise, distance (in points) angle, spread, blend, opacity, honor other effects: x offset, y offset, mode, knocked out, use global light, and effect color.
As you can see this can get a little crazy when it comes to writing a script. And, be careful, if you don’t get the syntax correct you can cause InDesign to crash big time. Besides, now that object styles have evolved to their present stateof glory why not just use object styles and let InDesign do all of the work behind the scenes.
When you manually create an object on an InDesign page, it assigns the object style for the object to “[None]” (unless you have somehow set a default object style for your document). To change drop shadow settings for object styles is a piece of cake, so this is now the preferred way to go. Besides, if you are going to export your document to HTML, you will want your objects to have object styles assigned.
Of course, to change drop shadow properties using an object style you are going to need to have a style set up with the drop shadow properties assigned the way you want for the change properties.
If you are a “hands-on” person, make sure you have no objects selected and select New Object Style from the panel’s context menu (fly-out). When the New Object Style dialog opens, make sure “[None]” is selected for Based On. Give your new style a name and set the properties for your drop shadow style.
For this, make sure that Object is selected in “Effects for” then check Drop Shadow. When you click on the words “Drop Shadow” the panel opens for setting Blending Mode, Opacity, Position, and so on. Note: to change color, you will most likely want to set Blending Mode to Normal then click on the color swatch indicator to the right of the Mode field. When complete click OK to return to your document.
Now, a find/change drop shadow script can make quick work of changing the drop shadow properties for your objects having a “[None]” object style. Just change the applied object style.
(*Assumes objects to find have "[None]" as assigned style and style with new drop shadow settings is named "Drop Shadow"*) (*optionSettings are for include footnotes, include hidden layers, include locked layers for find, include locked stories for find, include master pages*) set optionSettings to {false, true, true, false, true} tell application "Adobe InDesign CC 2015" set docRef to document 1 set findStyle to object style "[None]" of docRef set changeStyle to object style "Drop Shadow" of docRef set find object preferences to nothing set change object preferences to nothing set applied object styles of find object preferences to findStyle set applied object styles of change object preferences to changeStyle my setObjectOptions(optionSettings) tell document 1 set foundSet to find object if foundSet is not {} then change object set userMsg to " " & length of foundSet & " instances changed" else set userMsg to "No instances found having applied object style " & objStyleName end if end tell end tell activate display alert userMsg (*Sets properties for find change object option using list passed to handler**) on setObjectOptions(optionSettings) tell application "Adobe InDesign CC 2015" tell find change object options set include footnotes to item 1 of optionSettings set include hidden layers to item 2 of optionSettings set include locked layers for find to item 3 of optionSettings set include locked stories for find to item 4 of optionSettings set include master pages to item 5 of optionSettings end tell end tell end setObjectOptions
Working with object styles is so much easier than trying to set the drop shadow settings for fill transparency settings. You be the judge.