File Path to Image in InDesign Document

I’ve seen some scripts in the past that tried to swapped text placeholders into placed graphics in InDesign. I haven’t seen any lately for InDesign CS. Has anyone seen anything like this or would know how to configure it? I think the older scripts always placed an inline graphic where the text was. Ideally there would be a way for the script to read the text… match it with the real file path…change the placeholder bounding box to an image box… place the graphic file and… fit the image proportionately into the frame… repeat until done…

I’d be happy with the basic approach to this for now.

Did you ever figure this out? This is exactly my problem. I have a placeholder text that comes right after the “Very truly yours” line in a letter. I’d like to swap out that placeholder text with a signature tif file that will move as the text content of the letter changes.

A user in InDesign would normally just select the placeholder and then use the Place command (with “Replace Selected Item” selected). But I can’t seem to get the syntax right when scripting this command. I’m getting bogged down in creating and resizing rectangle elements which don’t seem to be inline in the text frame.

Any ideas? Thanks.

I solved the problem that I asked about in this thread. For the benefit of lurkers (of whom I am usually one), I post this simplified solution.

set sampleText to "Well, Prince, so Genoa and Lucca are now just family estates of the Buonapartes. But I warn you, if you don't tell me that this means war, if you still try to defend the infamies and horrors[PLACE GRAPHIC HERE] perpetrated by that Antichrist -- I really believe he is Antichrist -- I will have nothing more to do with you and you are no longer my friend, no longer my 'faithful slave,' as you call yourself! But how do you do? I see I have frightened you -- sit down and tell me all the news."

set GraphicInsertTag to "[PLACE GRAPHIC HERE]"

set myfile to choose file with prompt "Select a graphic file"

tell application "InDesign CS"
	--Just setting up a test document
	set myDocumentRef to make document
	set myPageHeight to page height of document preferences of myDocumentRef
	set myPageWidth to page width of document preferences of myDocumentRef
	tell page 1 of myDocumentRef
		set myX1 to left of margin preferences
		set myX2 to myPageWidth - (right of margin preferences)
		set myY1 to top of margin preferences
		set myY2 to myPageHeight - (bottom of margin preferences)
		set myTextFrame to make text frame with properties {geometric bounds:{myY1, myX1, myY2, myX2}}
		set contents of myTextFrame to sampleText
	end tell
	--This is where the place insertion takes place.  The trick is the "Tell selection" line.
	tell myDocumentRef
		select (search story 1 of myDocumentRef with find attributes {find text:GraphicInsertTag})
		tell selection of myDocumentRef
			place myfile
		end tell
	end tell
end tell