Help with Indesign CS4 Hyperlinks

Hi there i am hoping that someone can help:
I have written an applescript script to search a document, when the search text string matches the files loaded in a list from an external folder, a hyper link is created to this external file. see below:


set the_folder to choose folder
tell application "Finder"
	set files_list to every file of folder the_folder whose name extension is "pdf"
end tell

tell application "Adobe InDesign CS4"
	repeat with FileRef in files_list
		set FileName to name of FileRef
		set find text preferences to nothing
		--Search the document.
		set find what of find text preferences to FileName
		--Set the find options.
		set case sensitive of find change text options to false
		set include footnotes of find change text options to true
		set include hidden layers of find change text options to false
		set include locked layers for find of find change text options to false
		set include locked stories for find of find change text options to false
		set include master pages of find change text options to false
		set whole word of find change text options to false
		tell active document
			set myFoundItems to (find text) as string
			
			
			if FileName = myFoundItems then
				--
				set FileNewName to name of FileRef as string
				set TxtName to name of FileRef
				set TheURL to "files:files/" & FileNewName
				
				
				try
					set TheH to make hyperlink URL destination with properties {name:TxtName, destination URL:TheURL}
				on error
					set TheH to hyperlink URL destination TxtName
				end try
				
				set TheHS to make hyperlink text source with properties {name:myFoundItems, source text:myFoundItems, hidden:false}
				make new hyperlink with properties {destination:TheH, source:TheHS, visible:false}
				
				end if
			
		end tell
		
	end repeat
end tell

however I keep getting an error: “Adobe InDesign CS4 got an error: Can’t get hyperlink text source text expected but got "applescript.pdf".”

I can not figure it out as the text source is a string…
thanks

Keith

Hi,
Please check in event log of applescript and see where it get stuck.
Also try to execute the script after removing applescript.pdf.

Regards,
Poo