InDesign Problem with multiple Labels

I am trying to create a template to build real estate flyers from.

  • I use dialog boxes to capture the information to put in the template
  • I have an InDesign file with text boxes, each containing a script label
  • I call the script label (i.e. “MLSLabel” and search and replace the default text with the text gathered from the dialog box ansr1 and “Mapsco Coordinate” and search and replace the default text with the text gathered from the dialog box ansr2, and so on)
    the script below puts the right text from ansr1 in the first text box, but then it puts the right answer from ansr2 in the first text box, replacing the previous action, and then in the second text box where it belongs.
tell application "Finder"
	open document file "Leave-Behind template.indd" of folder "*Listings" of folder "Cheryls Folder" of folder "File Storage" of startup disk
end tell
tell application "InDesign CS"
	if exists document 1 then
		tell document 1
			set ASTID to AppleScript's text item delimiters
			set AppleScript's text item delimiters to ","
			set userInput1 to display dialog "8 digit MLS Number." default answer "Type Here"
			set ansrA to text returned of userInput1
			set theAnsr1 to ansrA
			set ansr1 to first text item of theAnsr1
			search "MLSLabel" for "12345678" replacing with ansr1
			set userInput2 to display dialog "Mapsco coordinate" default answer "Type Here"
			set ansrB to text returned of userInput2
			set theAnsr2 to ansrB
			set ansr2 to first text item of theAnsr2
			search "MapscoLabel" for "000" replacing with ansr2
		end tell
	end if
end tell

Well, the problem went away when I entered the third script label, and I have been loading the rest and testing after each, and the problem has not returned. This tells me my script, though it works, is tempermental, at best.

skip: A couple of notes…

  1. You say you’re building a template but the document you’re opening “Leave-Behind template.indd” is a document. Is this for testing purposes? If not, an InDesign template would have an extension of .indt.

  2. You are caching the current delimiter value (ASTID) but not resetting it. Make it a habit to always reset your delimiters when finished with them. Also, I’m not seeing why you’re using delimiters at all. Do you anticipate user input like “123,456,789” ?? Drop the delimiters unless you have a real need for them.

You’re doing alot of unnecessary coercions… userInput to ansrA to Ansr1 to ansr1. More simply…

set ansr1 to text returned of (display dialog ""8 digit MLS Number." default answer "Type Here")

  1. I don’t have ID in front of me right now but if you have tagged your text boxes then you can change the contents without doing a search.

Just a few suggestions. (I didn’t address all the issues I see because I didn’t want to overwhelm you all at once.)

Good Luck,
Jim Neumann