• 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
Re: text Encoding with Write to file
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: text Encoding with Write to file


  • Subject: Re: text Encoding with Write to file
  • From: jj <email@hidden>
  • Date: Mon, 09 Jan 2006 13:20:45 +0100
  • Thread-topic: text Encoding with Write to file

Well, I wouldn't rely on any tool to decide wheter a file is or not
MacRoman, as files are not one or other encoding, but only interpreted as
such. For example, I run this:

####################
set x to (path to desktop as text) & "untitled"
writeto(x, "§・")

on writeto(theFile, theContents)
    try
        set fd to open for access file theFile with write permission
        set eof of fd to 0
        write theContents to fd -- this will be UTF-16
        close access fd
    on error ErrMsg
        close access fd
        display dialog ErrMsg
    end try
end writeto
####################

It writes "§・" to the file. No problem.

Now, in a Terminal window:

####################
file ~/Desktop/untitled
####################

Returns "~/Desktop/untitled: ISO-8859 text, with no line terminators"

And:
####################
pico ~/Desktop/untitled
####################

Will show "??" (I think it doesn't show hi-ascii).

Now, if you open the file in TextEdit, it will open as MacRoman by default,
and you will see "§・". If you force-open it as ISO-8859 (or ISO Latin 1, or
whatever you call it), it will show "¤¥".

AppleScript will also read as mac-roman by default:

####################
set x to (path to desktop as text) & "untitled"
read file x --> "§・"
####################

But the fact is that the rigth characters were writen. That is hex 0xA4A5.

This is the behaviour in my machine ;-)


jj

> This Is not the problem.
> The script I send was for example and this source code never seen
> script editor on my machine.
>
> That write [...] as string will not return in an error is true.
> When the file contents start with §・  there is still no error but
> when you open the terminal and you type 'file path/to/filename' it
> will return 'binairy graphic metafile' and it has to be 'ASCII text,
> with CR, LF line terminators'.
> When you type 'pico path/to/filename' you will see that the text
> isn't MacRoman. That's why I was saying that 'write [...] as string'
> is not working.
> To make the encoding in MacRoman I added the iConv handler in the
> script example in the previous mail.
> But the question was can I do this last step directly in Script maker
> without using Iconv because write [...] as string is unreliable.
>
> BTW I have also Mac OS 10.4.3.
>
> Greetings Bastiaan
>
> Op 9-jan-2006, om 11:38 heeft jj het volgende geschreven:
>
>>> Well the problem is that I want to write a file with MacRoman text
>>> encoding. I found a lot on the internet and it doesn't work
>>>
>>> They said that write [...] as string will be MacRoman text encoding
>>> but this doesn't work.
>>
>> Works flawlessly here (OS X 10.4.3).
>>
>> Anyway, where are you writing your scripts. It's that the line:
>>
>> on write(theFile, theContents)
>>
>> Should compile as:
>>
>> on write {theFile, theContents}
>>
>> And overriding osaxen commands isn't considered a safe practice ;-)
>>
>> For instance:
>>
>> ###############################
>> on write {theFile, theContents}
>>     try
>>         set fd to open for access file theFile with write permission
>>         set eof of fd to 0
>>         write theContents to fd -- this will be UTF-16
>>         close access fd
>>     on error ErrMsg
>>         close access fd
>>         display dialog ErrMsg
>>     end try
>> end write
>> ###############################
>>
>> The line "write theContents..." should be calling to your handler
>> itself, as
>> you're fake-re-defining the meaning and usage of the command
>> "write". And,
>> as such, throwing an error, as "theContents to fd" doesn't match the
>> expected parameters for "on write {theFile, theContents}". On the
>> other
>> hand, if it would, you would have an infinite loop...


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >Re: text Encoding with Write to file (From: Bastiaan Boertien <email@hidden>)

  • Prev by Date: Re: text Encoding with Write to file
  • Next by Date: Re: "path to resource" in a tell Finder statement doesn't work
  • Previous by thread: Re: text Encoding with Write to file
  • Next by thread: Re: text Encoding with Write to file
  • Index(es):
    • Date
    • Thread