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:
David Livesay <[log in to unmask]>
Reply To:
Macintosh Scripting Systems <[log in to unmask]>
Date:
Thu, 16 Aug 2007 11:05:15 -0700
Content-Type:
text/plain
Parts/Attachments:
text/plain (122 lines)
Thank you all very much.

This particular script is a wrapper for a bunch of shell script snippets (written before I got comfortable with shell scripting--if one can ever be said to be comfortable with shell scripting). So it looks like the text returned from the shell scripts is UTF-16. That's another surprise to me, because UTF-8 is a sort of universal Unix convention. Files you create by redirection (i.e. > or >>) are UTF-8, at least I think so. Of course, if you cat a file that's UTF-16 and redirect it to a file it should still be UTF-16 unless you do something to convert it. In this script it just logs the result of runpsynch.

So what encoding does 'as string' give you, Mac Roman?
 
On Thursday, August 16, 2007, at 11:13AM, "Walter Ian Kaye" <[log in to unmask]> wrote:
>At 07:40 a -0700 08/16/2007, David Livesay didst inscribe upon an 
>electronic papyrus:
>
>>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?
>
>I don't think so.
>
>Is there anything in your script coercing to 'Unicode text'?
>
>Have you tried simply coercing to 'string' or 'text' before logging?
>
>If that doesn't work, there's always the TEC osax (does that work on Intel?).
>
>
>-boo

On Thursday, August 16, 2007, at 11:21AM, "Mark Lively" <[log in to unmask]> wrote:
>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

>On Thursday, August 16, 2007, at 12:27PM, "Emmanuel" <[log in to unmask]> wrote:
>
>Let me rephrase Mark's reply:
>
>write someStuff to someFile
>
>will make a UTF-16 file if someStuff contains Unicode text.
>
>So you *have* to specify, either:
>
>write someStuff to someFile as «class utf8» (since you seem to be 
>familiar with utf8)
>
>or, as advised by Mark:
>
>write someStuff to someFile as string
>
>Emmanuel
>
>

ATOM RSS1 RSS2