Annotate script from Shirley Hopkins creates too many text boxes

The following is a script called “Annotate” from Shirley Hopkins’ book “Applescripting Quark XPress”. I highly recommend this book, it is an amazing application-specific reference.

This script puts a text box with the Picture Name, scale factor and picture box dimensions over every picture box on a Quark document.

The problem I am having is that this script generates too many overlapping text boxes. The script is saying that there may be 20-30 picture boxes on my Quark document when there are only 4 or 5. So then the script generates an overlapping text box for each picture box that it “finds.”

Is there a way to only have one text box over each picture box? Why does the script say under the Event Log that I have so many picture boxes?

Any help would be appreciated.

–Herbert Ripka
Greendale, WI

tell application "QuarkXPress"
	if (document 1 exists) then
		tell document 1
			set properties to {horizontal measure:points, vertical measure:points}
			repeat with p from 1 to (count of pages)
				tell page p
					repeat with i from 1 to (count of picture boxes in it)
						if not (count of images in picture box i) = 0 then
							tell picture box i
								if not (bounds of image 1) = {0, 0, 0, 0} then
									set name of it to "p" & p & "picbox" & i
									set filevar to file path of image 1 of it as text
									set filename to my getfileName(filevar)
									copy (scale of image 1 of it as list) to {sc1, sc2}
									copy (width of bounds of it) to boxw
									copy (height of bounds of it) to boxh
									copy (origin of bounds of it as list) to {otp, olft}
									copy angle of image 1 to imangle
									set imangle to coerce (imangle as angle measurement) to string
								end if
							end tell
							
							make text box at beginning with properties {bounds:{otp, olft, ((otp as real) + 34), ((olft as real) + 72)}, color:"white", name:"annotate" & i, runaround:none runaround}
							tell (story 1 of text box ("annotate" & i))
								set contents of it to ("p" & p & "picbox" & i & return & filename & return & (sc1 as text) & " " & (sc2 as text) & " " & imangle & return & (boxw as text) & " " & (boxh as text))
								set properties to {font:"Helvetica", size:6}
								
							end tell
						end if
					end repeat
				end tell
			end repeat
		end tell
	else
		display dialog "Must have document with graphics open for this script to work"
	end if
end tell

on getfileName(path)
	set pathstr to (path as string)
	set lastColon to (offset of ":" in (reverse of (characters of pathstr)) as string) of pathstr
	return text from -(lastColon - 1) to -1 of pathstr
end getfileName

Does anyone have any answers to this one?

Is there a subroutine that I can add that would eliminate the duplicate boxes that this script creates?

Thank you for any help.

–Herbert Ripka
Greendale, WI