Re: Saving info to a newly created text file from within a script
Re: Saving info to a newly created text file from within a script
- Subject: Re: Saving info to a newly created text file from within a script
- From: kim <email@hidden>
- Date: Fri, 20 Jul 2001 10:25:50 +1200
G'day david
>
2) My first attempts at opening, writing, and closing a file ran into
>
errors after the file was opened but before the script closed the file. The
>
result was a file sitting there open on my desktop (i.e., unable to open
>
again, to delete, or whatever). How do I close this file without restarting
>
my Mac?
when writing to a file you really need to enclose it in a try block so if
it errors out, the file closes gracefully.
set thefile to ((path to desktop folder) & "Test file") as text
try
open for access file thefile with write permission
write "the text" to thefile
close access thefile
on error errmess
close access thefile
beep
display dialog "The file could not be written because of error: " &
errmess
end try
cheers
kim