Re: file is already open & file wasn't open
Re: file is already open & file wasn't open
- Subject: Re: file is already open & file wasn't open
- From: deivy petrescu <email@hidden>
- Date: Sat, 21 Apr 2007 15:57:16 -0400
On Apr 21, 2007, at 14:14, Michelle Steiner wrote:
On Apr 21, 2007, at 10:44 AM, deivy petrescu wrote:
You are not opening someFile, actually AS creates a reference to
the file someFile, a number, and it works with that reference
instead of the file.
So your command generates a number say 113, now AS will work with
113 not with someFile.
Once you have this problem, quit whatever is your Script Editor
and relaunch it.
Now you can try again, but you should use:
"set ofasF to open for access file someFile with write permission"
Actually, AS lets you reference the file either way.
write v : Write data to a file that was opened for access with
write permission
write anything : the data to write to the file
to anything : the file reference number, alias, or file reference
of the file to write to
Try this:
set foo to choose file name
set bar to open for access foo with write permission
write "hello world" & return to foo
write "goodbye cruel world" to bar
close access bar
Try this:
<script 1>
set foo to alias "HD:Users:user:Desktop:TUntitled.txt" -- file must
exist
set bar to open for access foo
try
write "Hello world" to foo
close access bar
on error e number n
display dialog e & return & n
try
open for access foo
close access bar
write "Hello world" to foo
on error e number n
display dialog e & return & n
end try
end try
</script1>
in another SE window run the following
<script2>
set foo to alias "HD:Users:user:Desktop:TUntitled.txt"
close access foo
set bar to open for access foo with write permission
-- error: File file BHD:Users:user:Desktop:TUntitled.txt is already open
write "hello world" & return to foo
write "goodbye cruel world" to bar
close access foo
</script2>
You can run script 1 again and again. No problem
But, run script 2.
Deivy
_______________________________________________
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