Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Open for access with write permission



>>>> I still get "File file Dora:Users:michelle:Desktop:en is already open."

Michelle, I notice your file is on the desktop. That makes it not simple.

I'm guessing that somewhere else in your script you're changing the
reference to that file.

Something like this?

set UserFile to (choose file with prompt "yadda") as string
set UserFile to file UserFile

That doesn't seem to work on the desktop.

Choose file returns an alias, so even if a file is on the desktop or moved
to the trash, AppleScript finds it.

This is how I always handle reading, writing, appending...

set UserFile to choose file with prompt "Please choose the file"
try
    set fileRef to open for access UserFile with write permission
on error
    close access UserFile
    try
        set fileRef to open for access UserFile with write permission
    on error errText number errNum
        display dialog "Couldn't open file because" & return & return &
errNum & " - " & errText
    end try
end try
set eof of fileRef to (get eof of fileRef)
write return & "extraStuff" & return to fileRef
close access fileRef  --that's what you meant, right? Not 'bar'


>>> If I put a close access statement right before the open access statement, I
get an error saying that the file isn't open.

Right, so I trap for that error. (I don't trap the close file first,  then
open the file, because the file usually isn't open, so the script usually
won't have an error.)

However, if that file is open by another application, you may get a
different error, so trap for that and see what it is.

Also, remember the close access command doesn't close access from another
script, or application, only the current script.
 
> If I omit "with write permission", I get an error on the next line saying that
it's not open with write permission.
  
  If you trap for that error, close the file and still get it, then
something else is going on.

>>In short, whether I try to open an existing file or create one from scratch, I
get that error.

Move the file off the desktop and empty the trash and I'll bet you get a
different result.

HTH and Good luck!

ES




 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/applescript-users/email@hidden
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.