Applescript: Indesign replace inline graphic with text

Hi All

I have a document with lots of inline graphics that have ‘script labels’ attached to them within text frames

I want to search for all of these and delete the graphic and insert into the text whatever was on the script label in its place.

So far I’ve found the positional reference and how to delete the graphic and add some text “ however I can’t link it all together :frowning:

Looking for help or direction

Shane

tell application "Adobe InDesign CC 2014"
	activate
	
	set AnchoredObjects to all graphics of stories of document 1
	
	-- this returns. {{}, {PostScript picture id 805 of rectangle id 804 of text from character 152 to character 152 of text flow id 784 of document id 1 of application "Adobe InDesign CC 2014"}}
	
	
	-- I need to get the Script Label from the inline graphic
	
	
	-- Use the position reference of the inline graphic above to delete it and insert what was on it's label
	tell parent story of text frame 1 of page 1 of document 1
		delete character 152
		set contents of insertion point 152 to "My Script Label Text"
	end tell
	--
end tell

HI. Assuming you’ve labeled the frame”rather than the image”the parent houses the label, and the grandparent is the insertion point

tell application "Adobe InDesign CS3"'s document 1 to repeat with target in (get stories's all graphics) --anchored objects
	set target's parent's parent's text to (target's parent's label) & " "
end repeat