MACSCRPT Archives

August 2007

MACSCRPT@LISTSERV.DARTMOUTH.EDU

Options: Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Subject:
From:
Mark Lively <[log in to unmask]>
Reply To:
Macintosh Scripting Systems <[log in to unmask]>
Date:
Thu, 16 Aug 2007 11:21:34 -0400
Content-Type:
text/plain
Parts/Attachments:
text/plain (81 lines)
On Aug 16, 2007, at 10:40 AM, David Livesay wrote:

> I opened some logs written by one of my scripts and found it was all  
> full of s?t?u?f?f? ?l?i?k?e? ?t?h?i?s?.?
>
> Turns out the files are all UTF-16. I generally use UTF-8 for  
> everything, and I see no real reason for writing plain old log files  
> in UTF-16. Mac OS Roman would be perfectly adequate, and somehow  
> seems more like what you'd expect to get from AppleScript.
>
> I can't find anything in the Language Guide that suggests you can  
> specify which text encoding to use. All it really says on the  
> subject is that "AppleScript provides partial support for...Unicode  
> Text," which they seem to equate with UTF-16. (Both UTF-8 and UTF-16  
> are Unicode.) In light of that, it seems odd that they would make  
> UTF-16 the default encoding when they say they only provide "partial  
> support," whatever that means, for it.
>
> Does anybody know if it's possible to set the default text encoding,  
> sort of like the way you can set the default text item delimiters?
>
Write to myFile as string

should do it for you.

This is my test script

set myData to "ab" as Unicode text
repeat 10 times
	set myData to myData & myData
end repeat

--group 1
set myFile to open for access (choose file name) with write permission
write myData to myFile  --none
close access myFile
set myFile to open for access (choose file name) with write permission
write myData to myFile as string --string
close access myFile
set myFile to open for access (choose file name) with write permission
write myData to myFile as Unicode text --Unicode
close access myFile

--group 2
set myData to myData as string
set myFile to open for access (choose file name) with write permission
write myData to myFile
close access myFile
set myFile to open for access (choose file name) with write permission
write myData to myFile as string
close access myFile
set myFile to open for access (choose file name) with write permission
write myData to myFile as Unicode text
close access myFile

--group 3
set myData to myData as Unicode text
set myFile to open for access (choose file name) with write permission
write myData to myFile
close access myFile
set myFile to open for access (choose file name) with write permission
write myData to myFile as string
close access myFile
set myFile to open for access (choose file name) with write permission
write myData to myFile as Unicode text
close access myFile



my results are

-rw-r--r--@ 1 lively  lively   4096 Aug 16 11:17 none1
-rw-r--r--@ 1 lively  lively   2048 Aug 16 11:17 none2
-rw-r--r--@ 1 lively  lively   4096 Aug 16 11:17 none3
-rw-r--r--@ 1 lively  lively   2048 Aug 16 11:17 string1
-rw-r--r--@ 1 lively  lively   2048 Aug 16 11:17 string2
-rw-r--r--@ 1 lively  lively   2048 Aug 16 11:17 string3
-rw-r--r--@ 1 lively  lively   4096 Aug 16 11:17 unicode1
-rw-r--r--@ 1 lively  lively   4096 Aug 16 11:17 unicode2
-rw-r--r--@ 1 lively  lively   4096 Aug 16 11:17 unicode3

ATOM RSS1 RSS2