Changing an InDesign text frame within an unnamed group

Is it possible to set the contents of a named text frame in InDesign that is grouped, even if the text frame is within an unnamed group?

I have a script that works fine as long as the script label is set for the group, but it requires ungrouping and regrouping multiple text frames. The problem comes in if the user manually ungroups and then regroups the text frames, in which case the group loses its script label. The user then gets an error with the script.


tell application "Adobe InDesign CS3"
	activate
	tell document 1
		set contents of parent story of text frame "theFrame" to textToInsert	-- won't work if this frame is within a group	
	end tell
end tell

Is there a way for the script to find the labeled text frame, even from within a group, to avoid this situation altogether?

I got it to work by looping through all of the groups that exist in the document, and looking in each one for the text frame I want. It works, but seems a little clunky, especially if there were several groups in the document. Is there a more direct way I’m missing?


set textToInsert to "My text"
tell application "Adobe InDesign CS3"
	activate
	tell document 1
		try
			set contents of text frame "theFrame" to textToInsert -- this makes sure "theFrame" hasn't been left ungrouped
		end try
		set allGroups to every group
		repeat with thisGroup in allGroups
			tell thisGroup
				set contents of parent story of text frame "theFrame" to textToInsert
			end tell
		end repeat
	end tell
end tell

OK here is a simpler way of referencing it:

tell application "Adobe InDesign CS3"
	set theGroups to parent of every text frame of every group of document 1 whose label is "mytxt" -- the group containing the text frame
	set theGroups to parent of every text frame of every group of document 1 whose label is "mytxt" -- the text frame
end tell

since we are specifying the text frames of a group you will not get text frames outside that group. So to set the text in all the occurrences of the named text box in every group the code would look like this:

set textToInsert to "My text"
tell application "Adobe InDesign CS3"
	set contents of every text frame of every group of document 1 whose label is "mytxt" to textToInsert
end tell