Re: When is a file open but not open?
Re: When is a file open but not open?
- Subject: Re: When is a file open but not open?
- From: deivy petrescu <email@hidden>
- Date: Sun, 7 Aug 2005 10:57:29 -0400
On Aug 6, 2005, at 10:08, Emmanuel wrote:
At 9:26 AM -0400 8/6/05, deivy petrescu wrote:
On Aug 6, 2005, at 4:56, Emmanuel wrote:
set r to open for access f with write permission
write {name:"deivy"} to r
write {name:"emmanuel"} to r
close access r
set r to open for access f
set x to read f as record
set x to read f as record
close access r
x's name
As per your request:
<script>
set pd to path to desktop as Unicode text
set r to ("" & pd & "testanu.txt") as alias
write {name:"Santos"} to r
write {name:"Santos Campeao"} to r
set x to read r as record
x's name
--> "Santos Campeao"
The game was not to print "Santos Campeao". It was to store several
records in one file (you store only one) and then retrieve, for an
example, the 2nd one.
Emmanuel
Emmanuel, you speak for yourself!
May game is to write "Santos Campeao" everywhere....
:)
You are right though! I cheated, to do that, read two records, or
records and lists without opening for access is possible and the
script is posted below (for the example above).
Now, the discussion here is why go over so much trouble if opening
for access works so much faster?
Because opening ad closing files for access might be problematic. If
there is an unsuspected error or something you are doomed. The file
will only be accessible by closing the app that opened it, in your
case Script Editor, I am sure. Since I am cleverer I use Smile... :)
I've been trapped in some instances of open for access gone wild and
it is absolutely miserable, principally because you are not humble
enough to know that we have to immediately quit the app and rerun the
script.
The script:
<script>
set pd to path to desktop as Unicode text
set r to ("" & pd & "testanu.txt") as alias -- file exists
set eof of r to 0
write {team:"Santos"} to r
write {title:"Campeão"} to r starting at eof
set lista to {}
set k to get eof of r
set ptt to path to "temp"
try
tell application "Finder" to make new file at ptt with
properties {name:"temporario"} --one can use do shell script to
create a file.
end try
set ptt to ("" & ptt & "temporario") as alias
set ini to 1
repeat with j from 1 to k
set eof of ptt to 0
write (read r from ini to j) to ptt
try
set x to read ptt as record
set end of lista to x
set ini to j + 1
end try
end repeat
-- one can remove temporario from temp.
lista
--{{team:"Santos"},{title:"Campeão"}}
</script>
There, I retrieved every record sent, as record!
Deivy _______________________________________________
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