Text editor incompatibilities problem

I have a shell script that creates a list of found InDesign files using TextEdit. But when I open it with Tex-Edit Plus to do some find/replace steps, there are problems. For some reason, the find/replace (actually looking for/replacing with) doesn’t find any numeric characters. For example, say I am searching for 3X12 (and it does exist in the file), I can’t find it. I can find the “X” though but not a 3 or 12. Now if I manually find (not with the find tool but scrolling until I see it) that 3X12 and copy it and then paste it into the Applescript to find, then it works. Anything typed in or copied from another text file doesn’t work.

Now if I take that TextEdit file and open it with Appleworks, select the text, and then save as plain text, my script works.

I just find it weird. Has anybody else ever had problems where find/replace doesn’t work when converting text files? Here’s a snippet of the code to give you an idea of what I am doing. Does anybody have any suggestions on doing this differently?


set files_ to paragraphs of (do shell script "find /Volumes/" & ArchiveName & " -type f -iname '*" & MacArtist & "*.indd' ! -iname '.*'")

if files_ is {} then
	display dialog MacArtist & " not found"
else
	set {TID, text item delimiters} to {text item delimiters, "/"}
	repeat with file_ in files_
		write_to_file((last text item of file_ & return), AdListFile, true) -- writes/creates the TextEdit file
	end repeat
	set text item delimiters to TID
end if
tell application "Tex-Edit Plus"
	activate
	open file AdListFile
	
	replace window 1 looking for "." replacing with tab -- this works fine
	
	replace window 1 looking for "1x1	C" replacing with "1_19" -- this doesn't work

Thanks for the help,
Mike

Hi, Mike.

Shell scripts return Unicode text and that’s presumably what’s being written to your file. Tex-Edit (4.9.7 at least) reads files as string, so it sees the Unicode’s high-order bytes as interpolated characters, which throws out the search. Your write_to_file() handler should ensure that the text is written to file as string (though you’'ll lose any Unicode-only characters in the process.)

Alternatively, you could miss out the file stage altogether and feed the text directly to Tex-Edit via AppleScript:

set myText to "Something" as Unicode text
tell application "Tex-Edit Plus"
	set myDoc to (make new document at front)
	set myDoc's text to myText
end tell