• 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
Closing a file you left open (error -49)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Closing a file you left open (error -49)


  • Subject: Closing a file you left open (error -49)
  • From: Ruffin Bailey <email@hidden>
  • Date: Tue, 19 Apr 2011 14:15:38 -0400

I've been trying to save out the contents of an Excel page to a specially formatted text file by iterating through its cells, and occasionally while I'm learning I run into an error, bust out of the script, and end up leaving a file open.  I've tried to catch errors and close the reference, but it doesn't appear to be working.  I've Googled up examples of closing files open in *another* application, but I don't see how to close one I've mistakenly left open.

So I'm essentially doing something like this:

set theText to "some text"
set theFilePath to (path to desktop as string) & "test.txt" as string
set theFileReference to open for access theFilePath with write permission
try
	write theText to theFileReference

	-- do more stuff

	write theText to theFileReference
	close access theFileReference
on error
	say "error"
	close access theFileReference
end try

If something borks in "do more stuff", I'm stuck with an endlessly open file.

Is there a way to check for an open file and then force it closed?  I've also tried closing the file in the start of the script by building another reference (and just ignoring the close if there's an error; say, the file's not open), but no luck there either.

Further, is there an easy way to get rid of the open file and start over?  I've tried deleting from the command line without luck; my script still sees the file open the next time I try.

Thanks,

Ruffin Bailey _______________________________________________
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: Closing a file you left open (error -49)
      • From: Luther Fuller <email@hidden>
    • Re: Closing a file you left open (error -49)
      • From: "Stockly, Ed" <email@hidden>
  • Prev by Date: Re: Excel: hide multiple columns with Applescript
  • Next by Date: Re: Closing a file you left open (error -49)
  • Previous by thread: Re: system services ?
  • Next by thread: Re: Closing a file you left open (error -49)
  • Index(es):
    • Date
    • Thread