writing Unicode to an existing Unicode text file on Intel Macs
writing Unicode to an existing Unicode text file on Intel Macs
- Subject: writing Unicode to an existing Unicode text file on Intel Macs
- From: Donald Hall <email@hidden>
- Date: Wed, 7 Nov 2007 23:46:08 -0700
Has anyone come across the following problem before on Intel Macs,
and if so, is there a fix?
1. Open a new plain text file in TextEdit and add a few words (say,
"This is unicode text").
2. Save the file as Unicode UTF-16.
3. Create and run the following script:
-- Unicode writing test script ---------------------------------
set theFile to (path to home folder as text) & "unicode test.txt"
set theText to "added unicode text" as Unicode text
set fref to open for access file theFile with write permission
try
write theText as Unicode text to fref starting at eof
end try
close access fref
set fref2 to open for access file theFile with write permission
try
set theContents to (read fref2 as Unicode text)
end try
close access fref2
theContents
-- end script --------------------------------------------------
Test Results
Test 1: -- file initially contains the words "This is unicode text"
Script Result:
"This is unicode text <plus Japanese characters>"
Contents of file upon re-opening in TextEdit: Same as script result
Test 2: -- file starts empty (but encoding is still UTF-16)
Script Result:
"added unicode text"
Contents of file upon re-opening in TextEdit: <same Japanese
characters as above>
Test 3: -- file does not exist, created by AppleScript
Script Result:
"added unicode text"
Contents of file upon opening in TextEdit: