• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
writing Unicode to an existing Unicode text file on Intel Macs
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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:

added unicode text *** but file appears to be Mac OS Roman ***

Note that the script works fine on a PPC Mac, giving the expected result. On an Intel Mac it looks like an endian problem. Is there any way around this in AppleScript? ISTR AppleScript always uses big endian for UTF-16.


Thanks,

Don


-- Donald S. Hall, Ph.D. Apps & More Software Design, Inc. email@hidden http://www.appsandmore.com _______________________________________________ Do not post admin requests to the list. They will be ignored. AppleScript-Users mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden
  • Follow-Ups:
    • Re: writing Unicode to an existing Unicode text file on Intel Macs
      • From: Christopher Nebel <email@hidden>
  • Prev by Date: ANN: MetaData.osax 1.0.7 update for Mac OS X 10.5
  • Next by Date: RE: do shell problem
  • Previous by thread: ANN: MetaData.osax 1.0.7 update for Mac OS X 10.5
  • Next by thread: Re: writing Unicode to an existing Unicode text file on Intel Macs
  • Index(es):
    • Date
    • Thread