In response to a segment on “Live Captions” (InDesignSecrets-146 podcast), I would like to contribute an applescript that I have used since CS3 and now use it in CS5. Perhaps someone can rewrite it to a javascript format and share it. The script may be considered crude and does not have a lot of “bells and whistles,” but serves the user well.
Using metadata info would be great for populating image captions…but in my limited publishing world, no one completes this info. Generally the various editors I deal with just ‘throw’ their images at me to place (most are ‘editors’ by name only).
I personally use a strict ‘align to baseline’ layout. Once I’ve placed the many images needed to complete a chapter section, I then run my script to place a text box below any selected images. The text box is then set to the same width as the image container. The script will then populate the text box with “XXXXXXXX” generic text. It will check for a specific paragraph style to use (if not found, the script will create it). When this is done, I return to each photo and enter the caption text provided by the editor. The script can be edited to modify the depth of the text box and whether or not to apply text wrap.
Further more, the script will label each text box so that in the event the editor requests a different layout design, I can remove all the caption boxes with another script I’ve written and start again.
This script has saved me a great deal of time. I hope it will be of use someone! Let me know if it helps you!
= = = = Start of Script
(* ADD • Photo Caption to Boxes.scpt *)
— This script will add caption text boxes to selected photo containers.
set styleName1 to “Photo Captions”
tell application “Adobe InDesign CS5”
activate
–CHECK FOR OPEN DOCUMENT
if not (exists document 1) then
beep
display dialog “Please open a document and try again!” buttons “Cancel” default button “Cancel” with icon 1
return
end if
set theDoc to active document
–CHECK IF A SELECTION IS TRUE
if not (exists selection) then
beep 1
display dialog “Please make a selection and try again!” buttons “Cancel” default button “Cancel” with icon 1
return
end if
set mySelection to selection
set thePage to active page of active window
–CHECK FOR EXISTING PARAGRAPH STYLE
if (exists paragraph style styleName1 of theDoc) is false then
try
tell theDoc
set styleName1 to make paragraph style with properties {name:styleName1, applied font:”Verdana”, font style:”Bold”, point size:10.0, justification:center align, leading:auto, tracking:100.0, horizontal scale:80.0, kerning method:”Optical”}
end tell –theDoc
end try
end if
–BASELINE DEFAULTS IN USE
set myCaptionHeight to “2p0” — STANDARD MAGAZINE
–set myCaptionHeight to “2p2” –VERSION 1 MAGAZINE
–set myCaptionHeight to “2p4” –VERSION 2 MAGAZINE (11/14 leading)
tell theDoc
— GET CURRENT UNIT OF MEASURE SETTINGS BEFORE ADDING LINE
set {oldHorz, oldVert} to {horizontal measurement units of view preferences, vertical measurement units of view preferences}
— SET THE NEW UNIT OF MEASURE
set the properties of view preferences to {horizontal measurement units:points, vertical measurement units:points, ruler origin:page origin}
set zero point of theDoc to {0, 0}
set myItemCount to count mySelection
–return myItemCount
— = = = = = = = = = =
repeat with eachItem in mySelection
set properties of view preferences to {ruler origin:spread origin}
set myItem to eachItem
— GET NEW GEOMETRIC BOUNDS OF THE SELECTION
copy geometric bounds of myItem to myBounds
set tp to item 1 of myBounds — y1
set lft to item 2 of myBounds — x1
set bot to item 3 of myBounds — y2
set rt to item 4 of myBounds — x2
set theSelWidth to (rt – lft)
— GET GEOMETRIC BOUNDS OF THE SELECTION (used to reset zero point location)
set zero1 to (item 3 of myBounds) — y1
set zero2 to (item 2 of myBounds) — x1
–SET THE ZERO POINT RULER TO TOP/LEFT EDGE
set zero point of theDoc to {zero2, zero1}
select nothing
— MAKE PHOTO CAPTION BOX
tell thePage
–NO TEXT WRAP APPLIED
–set theCaptionBox to (make text frame with properties {geometric bounds:{0, 0, myCaptionHeight, theSelWidth}, fill color:swatch “None” of theDoc, stroke alignment:inside alignment, stroke color:swatch “Black” of theDoc, stroke tint:100, stroke weight:0, label:”CaptionBox”, applied paragraph style:”Photo Captions”, contents:”XXXXXXXXXXXXXX”})
–TEXT WRAP IS APPLIED
set theCaptionBox to (make text frame with properties {geometric bounds:{0, 0, myCaptionHeight, theSelWidth}, fill color:swatch “None” of theDoc, stroke alignment:inside alignment, stroke color:swatch “None” of theDoc, stroke tint:100, stroke weight:0.0, label:”CaptionBox”, applied paragraph style:”Photo Captions”, contents:”XXXXXXXXXXXXXX”, text wrap preferences:{text wrap offset:{0.0, 0.0, 0.0, 0.0}, text wrap side:both sides, inverse:false, «class txwt»:«constant txwebsds»}})
end tell –thePage
select theCaptionBox
tell theCaptionBox
–SET APPLIED PARAGRAPH STYLE OF PARENT STORY TO “PHOTO CAPTION”
try
set applied paragraph style of parent story to “Photo Captions”
end try
end tell –theCaptionBox
set zero point of theDoc to {0, 0}
set properties of view preferences to {ruler origin:page origin}
end repeat
— = = = = = = = = = =
— RESET CHANGES
— RESET THE UNIT OF MEASURE TO ORIGINAL SETTING
set the properties of view preferences to {horizontal measurement units:oldHorz, vertical measurement units:oldVert}
–RETURN ZERO POINT TO ORIGINAL 0,0
set zero point of theDoc to {0, 0}
select nothing
beep 1
end tell –theDoc
end tell –application
= = = = End of Script