file is already open & file wasn't open
file is already open & file wasn't open
- Subject: file is already open & file wasn't open
- From: Gil Dawson <email@hidden>
- Date: Fri, 20 Apr 2007 15:23:24 -0700
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?
--Gil
_______________________________________________
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