Re: creating text file under Tiger 10.4.1?
Re: creating text file under Tiger 10.4.1?
- Subject: Re: creating text file under Tiger 10.4.1?
- From: Paul Berkowitz <email@hidden>
- Date: Wed, 06 Jul 2005 12:12:15 -0700
- Thread-topic: creating text file under Tiger 10.4.1?
On 7/6/05 11:45 AM, "Guillaume Iacino" <email@hidden> wrote:
> Did Tiger change or break something in the way to create and write to
> a text file.
>
> Under 10.3.9, the following script works.
>
> ///
> set this_data to "My text"
> set targetREF_file to "HD:Folder:File.txt" as text
>
> set the open_target_file to open for access file targetREF_file with
> write permission
>
> write this_data to the open_target_file starting at 0
> set eof open_target_file to (length of this_data)
> close access the open_target_file
> ///
>
> This is supposed to create a text file at targetREF_file and write
> this_data in it.
>
> Under 10.4.1, the text file seems to be created fine, but only half
> of the text is added to the text file. Very odd. Furthermore, the
> icon of the file looks like an OS 9 icon.
>
> I've heard that 10.4.1 has several Applescript bugs, and that 10.4.2
> was supposed to fix more than 100 issues. Is this one of them?
It works fine here in 10.4.1. Have you really tried out that exact script?
Do you really only see "My t" or "My " rather than "My text"?
Or is your problem with a script using different text?
Here's what I think has happened:
In OS 10.4, concatenating Unicode text with string results in Unicode text
even where the bit on the left side of "&" is string. (Before 10.4, the
concatenation rule said that the concatenated text coerced to the same class
as the leftmost object, so if it started as string you ended up with string
as long as the Unicode bit could be coerced.)
So I think you must have - somewhere in the text - some Unicode text that
came from an application you're scripting. So now the entire text is
Unicode, not text.
Since you have not coerced this_data to string or text, and you have not
specified 'write to file as string' either, it's writing it using the
Unicode bytes (which includes interpolated ASCII 0 characters between each
string character) - twice as many bytes.
But AppleScript will count the just the number of characters, not bytes,
when you ask for 'length of this_data' - so that's half as many. When you
set eof to that number of bytes, it cuts it in half.
If you read back from the file, without specifying read as Unicode text',
you're going to see an empty space between each character. (If you specify
'as Unicode text' it will look OK.)
In this case you probably want to coerce to string before writing, or else
do everything as Unicode text but don't set eof to the length in that case.
--
Paul Berkowitz
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
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