Hi all, this forums has been a great help to me in the past, and I am hoping that someone can solve my current conundrum again!
I have a script that is working as part of a fairly complicated widget that basically takes text from an application and displays it. This text, however, can be just English, but it could also include other unicode languages or symbols. In Tiger, the code was working fine. My basic solution (since passing Unicode through a prompt to my widget corrupted the text) was to write the text to a file, then have the widget read the file. Here is my old writing code, taken, I think from somewhere on these forums:
on write_to_file(the_file, the_data, with_appending, isEnglish)
set the_file to the_file as string
try
set f to open for access file the_file with write permission
if with_appending = false then set eof of f to 0
if not isEnglish then write ((ASCII character 254) & (ASCII character 255)) to f -- add 0xFEFF BOM
write the_data to f starting at eof as (class of the_data)
close access f
return true
on error the_error
try
close access file the_file
end try
return the_error
end try
end write_to_file
isEnglish is a boolean which tells whether or not I’m passing only English, so whether or not it has to be a Unicode written file. I can’t remember if there is a reason I didn’t want the English to be unicode or not, but its not important; for now I can get rid of the distinction.
My problem I think lies in my BOM marker. Ever since going to leopard, it is misreading my BOM marker, turning all of my text into an Asian script. If I have it write the marker even on English, it still turns it into the other script. Now, I can get rid of the BOM writings, so the English is displayed fine, but then all of the upper Unicode is now just ‘???’
What can I do, such that I can still write Unicode text to the file consistently? I know the text is arriving to the function fine as I’ve had it get returned immediately, and it is still correct. By the way, the_data has been previously defined by ‘as Unicode text’. Oh, secondarily by the way, this script needs to remain backwards compatible, even if that means maintaining 2 sets of code with an OS toggle switch. Thanks so much!