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: Fri, 5 Aug 2005 11:58:52 -0400
On Aug 5, 2005, at 10:32, Gary (Lists) wrote:
"deivy petrescu" wrote:
John,
I've tried as much as I could to avoid using "open for access".
It always ends up causing problems.
Somethings you can do to avoid the problem:
a. close access to the file before you open.
b. when you close a file, do it twice.
Now, the best thing to avoid any problems is to avoid it altogether.
And, you can avoid it.
You can simply write to a file without opening it.
This is the script:
<script>
set pd to path to desktop as Unicode text
set pd to ("" & pd & "testanu123.txt")
tell application "Finder"
try
close access alias pd
end try
set j to open for access alias pd with write permission
close access j
end tell
write ("This is a test" & return) to file pd
write ("This is another test" & return) to file pd starting at eof
</script>
Deivy, I don't understand. You said "without opening it", but you
use 'open
for access'. Am I missing something clever? Or do you mean that
you just
open then immediately close the file, in order to gain a usable
reference
for 'write'?
--
Gary
Gary
I opened and closed the file for two reasons.
Opening for access creates a file if it does not exist (at least for
now, originally it did create the file, then for a while it did not,
now it does again!).
Also, I wanted to show what to do if you are "opening a file", that
is, close it first. I forgot to close it twice as I suggested.
But no, you do not have to open a file then close it.
Create a file on your own, say "testanu123.txt" in your desktop. Then
run the script:
<script>
set pd to path to desktop as Unicode text
set pd to ("" & pd & "testanu123.txt")
write ("This is a test" & return) to file pd
write ("This is another test" & return) to file pd starting at eof
</script>
By the way, if you run now the following script;
<script>
set pd to path to desktop as Unicode text
set pd to ("" & pd & "testanu123.txt")
write ("This is the first line" & return) to file pd
write ("This is another test" & return) to file pd starting at eof
</script>
what you get is the following
first run --> This is a test
This is another test
second run --> This is the first line
This is another test
This is another test
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