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: Guillaume Iacino <email@hidden>
- Date: Wed, 6 Jul 2005 15:05:59 -0400
Andrew,
Thank for your quick reply AND your solution. Works great!
I've been using this code for several weeks but never had this issue
before moving to 10.4. Nice catch.
Thanks again for your help!
Guillaume
On Jul 6, 2005, at 2:57 PM, Andrew Oliver wrote:
On 7/6/05 11:45 AM, "Guillaume Iacino" <email@hidden> wrote:
Hi,
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?
Thank you in advance for your insights,
Regards,
Guillaume
The pertinent part of your question is the statement "but only half
of the text is added to the text file"
Your problem is almost certainly one of "length of this_data"
returning the
number of characters in the string rather than the number of bytes
written
to the file. If using unicode text, for example, the number of
characters
might not equal the number of bytes required to write the data to
disk.
I'm surprised you haven't encountered this in the past.
The solution is to NOT write the EOF. Just clear it before you
write the
data. The 'write' command will automatically increment the EOF
based on the
data you're writing, so instead of:
write this_data to the open_target_file starting at 0
set eof open_target_file to (length of this_data)
You should:
set EOF open_target_file to 0 -- reset the EOF
write this_data to the open_target_file -- write the data
The EOF is automatically incremented and the file contains the data
you
expect.
Andrew
:)
_______________________________________________
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