Re: open for access file
Re: open for access file
- Subject: Re: open for access file
- From: "Mark J. Reed" <email@hidden>
- Date: Fri, 17 Jul 2009 19:55:48 -0400
That applies to reading, too. After running your script:
tell application "Finder"
set someFile to file "Mytest1.txt" of desktop as alias
end tell
open for access someFile
try
log (read someFile)
log (read someFile)
on error message
display dialog message
end try
close access someFile
tell application "Finder"
set someFile to file "Mytest2.txt" of desktop as alias
end tell
log (read someFile)
log (read someFile)
log (read someFile)
Basically, without open, you get the whole file in one go. Writing
will create it or replace its entire contents, while reading will
return the whole file. Either action is idempotent: you can do it as
many times as you like with no change in the result.
Open for access introduces state. After you read or write, the file
is still open, but at the end. So another write will append, while
another read will signal end-of-file.
On Fri, Jul 17, 2009 at 7:15 PM, Stockly, Ed<email@hidden> wrote:
>
>
>
>>> You must open for access to write to a file however.
>>
>> Not really:
>
>
> Cool.
>
> This illustrates the difference.
>
> ES
>
> tell application "Finder"
> set someFile to (make file at desktop with properties
> {name:"Mytest1.txt"}) as alias
> end tell
> open for access someFile with write permission
> write "Here is some texta" to someFile
> write "Here is some textb" to someFile
> write "Here is some textc" to someFile
> write "Here is some textd" to someFile
> close access someFile
>
> tell application "Finder"
> set someFile to (make file at desktop with properties
> {name:"Mytest2.txt"}) as alias
> end tell
> write "Here is some texta" to someFile
> write "Here is some textb" to someFile
> write "Here is some textc" to someFile
> write "Here is some textd" to someFile
>
> _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> AppleScript-Users mailing list (email@hidden)
> Help/Unsubscribe/Update your Subscription:
> Archives: http://lists.apple.com/archives/applescript-users
>
> This email sent to email@hidden
>
--
Mark J. Reed <email@hidden>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden