• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: file is already open & file wasn't open
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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
  • Follow-Ups:
    • Re: file is already open & file wasn't open
      • From: Michelle Steiner <email@hidden>
References: 
 >file is already open & file wasn't open (From: Gil Dawson <email@hidden>)
 >Re: file is already open & file wasn't open (From: deivy petrescu <email@hidden>)
 >Re: file is already open & file wasn't open (From: Michelle Steiner <email@hidden>)

  • Prev by Date: Re: file is already open & file wasn't open
  • Next by Date: Re: file is already open & file wasn't open
  • Previous by thread: Re: file is already open & file wasn't open
  • Next by thread: Re: file is already open & file wasn't open
  • Index(es):
    • Date
    • Thread