Replace text w/ Graphics Can This been done

I trying to write an applescript that will search a document with several text boxes and replace the given text with an image file. (example text box with a number in it 1, 2, 3, 4, 5 or 6 and replace that number with a corresponding eps file 01.eps, 02.eps, 03.eps, 04.eps, 05.eps, or 06.eps. Can this been done or am I just wasting my time? My attempts at this just highlight the text and stop. I’m trying to do this in Indesign CS 2. Any help would be greatly apperciated.

Thanks
fishheadtw

This is where I am as of today:

global foundPaths, foundPathNames
set foundPathNames to {}
set foundPaths to {}
tell application “Adobe InDesign CS2”
set folderpath to (choose folder with prompt “Choose the Folder Containing the New EPS Files”) as Unicode text
set mydoc to active document
tell mydoc
activate every text frame of page 1 in mydoc
set TextFrame to every text frame of page 1 in mydoc
repeat
set selection to search TextFrame for “2”
set selvariable to selection as list
if selvariable = “” then
exit repeat
replace “01.eps”
end if
end repeat
end tell
end tell

A quick attempt at getting you a bit further along. Note, it you do not want to set the bounds of the inline box untill after it has been created.

tell application "InDesign CS"
	activate
	tell document 1
		set TheTextFrame to text frame 1
		set TheWords to search TheTextFrame for "1."
		repeat with i from (count of TheWords) to 1 by -1
			set CharacterBefore to (index of character 1 of item i of TheWords) - 1
			set contents of item i of TheWords to ""
			tell parent of item i of TheWords
				make rectangle at insertion point 2 of character CharacterBefore with properties {content type:graphic type}
			end tell
		end repeat
	end tell
end tell