FIND & CHANGE INDESIGN CS

I tried to write a script so that I can drop all my pages and it will process all pages + find and change some corrections, but there seems to be a problem with saving file, anyone knows how o resave file???

on open sourceFolders
repeat with sourceFolder in sourceFolders
tell application “Finder”
try
– If you would like to include subfolders, you say - every file of entire contents of folder…
set idFiles to (every file of folder sourceFolder whose file type is “IDd3”) as alias list
on error – work around bug if there is only one file
set idFiles to (every file of folder sourceFolder whose file type is “IDd3”) as alias as list
end try
end tell

	if idFiles is not {} then
		tell application "InDesign CS"
			
			repeat with i from 1 to count of idFiles
				open item i of idFiles
				tell document 1
					activate
					set find preferences to nothing
					set change preferences to nothing
					set myDocument to document 1
					try
						--find out if text is selected so that we can adjust the dialog to search Document or Story
						set theClass to class of item 1 of selection
						if theClass is in {text, text frame, insertion point} then
							set searchOptions to {"Document", "Story"}
						end if
					on error
						set searchOptions to {"Document"}
					end try
					repeat
						try
							set myfoundspaces to search document for "NC" replacing with "9N"
							if myfoundspaces = {} then
								exit repeat
							end if
						on error
							exit repeat
						end try
					end repeat
					
				end tell
				close with saving
				
			end repeat
			set user interaction level to interact with all
		end tell
	end if
	return 10 -- try again in 10 seconds 
end repeat

end open

The Save method for a document requires a reference to where you want to save it to. You have the alias…es?..Aliai? Whatever the plural is for alias, you already have them in a list. Maybe coerce it to text and point the app back to where the document is. The InDesign Scripting Guide says that “if the document is already saved, a copy is saved at this path, the original file is closed the new copy is opened [sic]” So…

tell “InDesign CS”
–your code here opens the file and does the actions.
–the line “close with saving” becomes this:
set filePath to item x of idFiles --basically whichever document it’s currently processing
tell active document
save to (filePath as text)
end tell
close active document
end tell

I haven’t tested this particular example, but “save to (filePath as text)” is the way I do it.