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: Arnaud Nicolet <email@hidden>
- Date: Sat, 21 Apr 2007 01:31:12 +0200
Hi,
I read somewhere that a major difference between Mac OS X and Mac OS
9 is that, under Mac OS X, you can now open a file for access even if
it is already open by another application (I think the last to close
it makes the changes) while it was not possible under OS 9 and earlier.
That certainly explains the difference you are encountering (your
file might even be opened for access in both OS but only Mac OS 9
reports an error).
Le 21 avr. 07 à 00:23 Matin, Gil Dawson a écrit:
Hi, folks--
I'm trying to port a procedure that works in Tiger to MacOS 9.2.2
(Script Editor 1.8.3) and I'm having trouble remembering the
ancient incantations...
This works in 10.4.9:
to Append onto someFile from someText --rev 1/1/07
try
open for access file someFile with write permission
on error errm number errn
if errn = -38 then -- file was already open
close access file someFile
open for access file someFile with write permission
else
error errm number errn
end if
end try
set FileNr to result
write someText to FileNr starting at ((get eof FileNr) + 1)
close access FileNr
end Append
However, in 9.2.2, this:
set someFile to
"Max106:Applications:MacHTTP:Projects:GoogleMaps:GilLog.log"
tell application "Finder" to ¬
exists file someFile
try
set FileNr to open for access file someFile with write permission
on error errm number errn
log "Error= " & errm & ". Number=" & errn
if errn is in {-49, -38} then -- file was already open
try
close access file someFile
open for access file someFile with write permission
on error errm2 number errn2
log "Error2= " & errm2 & ". Number=" & errn2
end try
else
error errm number errn
end if
end try
Produces the following log:
tell application "Finder"
exists file
"Max106:Applications:MacHTTP:Projects:GoogleMaps:GilLog.log"
--> true
end tell
tell current application
open for access file
"Max106:Applications:MacHTTP:Projects:GoogleMaps:GilLog.log" with
write permission
(*Error= File file
Max106:Applications:MacHTTP:Projects:GoogleMaps:GilLog.log is
already open.. Number=-49*)
close access file
"Max106:Applications:MacHTTP:Projects:GoogleMaps:GilLog.log"
(*Error2= File
Max106:Applications:MacHTTP:Projects:GoogleMaps:GilLog.log wasn't
open.. Number=-38*)
end tell
So I can't open it because it is already open and I can't close it
because it wasn't open. I must be overlooking something.
Anyone remember what it is? What is 9.2.2 error code -49?
_______________________________________________
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