Hiya,
I haven’t been able to do any scripting for a while so I’ve just gotten back to this. Originally I was making a script that scattered loose images from scratch so I was interested in labeling the images as they were laid up on the page, not afterwards. However I’ve lost the script, which worked pretty well, so doing the text label in the loop isn’t an issue now.
Thank you all so much for the script samples; I appreciate the help. I ended up modifying a script I had found some time ago and it’s appearently working ok.
mleslie, your script was failing on multiple page documents, but it helped me figure out how to get the scaling factor. Thanks again to all (and kai for some previous date coercion stuff in other threads.) Here’s the script that appears to work for me, except that I haven’t quite figured out how to get it to tighten the kerning up to always fit in the label box.
set {month:m, day:d, year:y} to (current date)
set theDate to (m * 1 & "." & d & "." & y) as string
log theDate
tell application "InDesign CS"
tell document 1
tell view preferences
set horizontal measurement units to points
set vertical measurement units to points
end tell
try
set labelStyle to make character style with properties {name:"Mononoko", applied font:"Monaco", font style:"Regular", point size:10, fill color:"Black"}
on error
set labelStyle to make character style with properties {name:"Mononoko", applied font:"Monaco", font style:"Regular", point size:10, fill color:"Black"}
end try
--myLinksName is the name of the layer containing the links tags.
set myLinksName to "Links Names"
try
--Get the layer on which to place the links tags.
set myLayer to layer myLinksName
on error
--Create the layer if it didn't already exist.
set myLayer to make layer at beginning with properties {name:myLinksName}
end try
repeat with i from 1 to count of links
set imageClass to class of parent of link i
if imageClass is in {PDF, image, EPS} then
set picFrame to parent of parent of link i
set LinkName to name of link i
set imageStats to horizontal scale of parent of link i
set linkNameLen to length of LinkName
set theBounds to geometric bounds of picFrame
set theBounds to {(item 3 of theBounds) + 2, item 2 of theBounds, (item 3 of theBounds) + 20, (item 4 of theBounds) + linkNameLen + 26}
repeat
set theClass to class of picFrame
if theClass is in {page, spread} then
set theTarget to picFrame
exit repeat
else if theClass is in {character, text, insertion point} then --
inline
set picFrame to parent text frame of character 1 of picFrame
else
set picFrame to parent of picFrame
end if
end repeat
set labelFrame to make text frame at theTarget with properties {geometric bounds:theBounds, label:"Pic label", contents:{LinkName & " @ " & imageStats & "%" & " " & theDate} as text, item layer:myLayer, text wrap preferences:«constant tilpnone»}
set properties of text frame preferences of labelFrame to {inset spacing:{"0p1", "0p1", "0p2.5", "0p1"}, vertical justification:«constant cnalcent», ignore wrap:true}
end if
end repeat
end tell
beep
with timeout of 30 seconds
display dialog "May You Always Know What Image Is Placed." buttons {"OK"} default button 1
end timeout
end tell
aaron