Bizarre text file saving/ extra characters

I am using A-Studio (OSX 10.39) to open a ‘dialog box’, the user can input or change a significant amount of text (NS text view), and then it’s automatically saved. When I close the box then, the text is saved but after every character there are 3 characters that are completely invisible. I can only tell they are there by re-opening the text file, and using forward or back arrow, and it takes 4 presses to make the cursor move past 1 character. I can’t copy or paste this text into any other program, I only get the first character, unless I take out (by using the forward or back delete key) the extra hidden characters. Also the more times I open and close my text window, the more extra invisible characters are inserted between each regular character, each open/close results in doubling the number of invisibles.
Can anybody shed any light on what might possibly be going on?

Here is the script I use to open the window and save its contents on closing:

on clicked theObject 
	show window "FTP Site List" 
	set FTPListPath to path for resource "ftpsource" extension "txt" 
	set myFTP to read file ((POSIX file FTPListPath) as string) 
	set contents of text view "inner" of scroll view "ftpeditwindow" of window "FTP Site List" to myFTP 
end clicked 

on will close theObject 
	set FTPListPath to path for resource "ftpsource" extension "txt" 
	set myNewFTP to contents of text view "inner" of scroll view "ftpeditwindow" of window "FTP Site List" 
	write myNewFTP to file ((POSIX file FTPListPath) as string) 
end will close

The window just has an NS Text View box on it, and the “inner” is the ‘inside’ part of the NSTextView box, since it seems like that actually handles the text display.

First, try explicitly coercing your text to a string before writing it to file. Also, use the ‘content’ rather than the ‘contents’ of a text view to get it’s plain text, as the contents property can return unexpected values sometimes. Try using the following in your will close handler instead…

on will close theObject
	set FTPListPath to path for resource "ftpsource" extension "txt"
	set myNewFTP to (content of text view "inner" of scroll view "ftpeditwindow" of window "FTP Site List") as string
	write myNewFTP to file ((POSIX file FTPListPath) as string)
end will close

Let us know if that helps. Otherwise we may need to see the output, or perhaps even the whole project to see what’s really going on.

j

Thanks Jobu,
that seems to have fixed it. :smiley:
-Chris