Indesign CS search & replace with inline image

some time ago i made a script for indesign 2.0 that searches a text frame for the character “#” and replaces it with an inline image that is stored on the clipboard. I tried the script with Indesign CS but it doesn’t work. I’ve tried multiple variations, but can’t seem to make it work. Does anyone have an idea or can someone help me out?

Here’s the script I’ve written before

tell application “Indesign CS”
set sjab to active document
tell sjab
activate first text frame of page 1 in sjab
set TextFr1 to first text frame of page 1 in sjab
set selection to search TextFr1 for “#s
set sel_var to selection as string
if sel_var = “” then
exit repeat
end if
end repeat
end tell