I am having problems writing out the contents of an XML file that has
been parsed in using XML suite to a new file. Using a test app, shown
below, I consistently get the error message:
An error was encountered writing the file to: "my file path". Error:
System Events got an error: File some object wasn't open.
The test app code is shown below:
------------------------------------------
set thePodcast to ""
set xmlFile to "/Path/To/XMLFILE/file1.xml"
tell application "System Events"
set thePodcast to (contents of XML file xmlFile)
end tell
set posixPath to "/Path/To/XMLFILE/file2.xml"
set file_path to POSIX file posixPath
try
set open_file to open for access file_path with write permission
set eof of the open_file to 0
write thePodcast to open_file starting at eof
close access file file_path
The word "file" in that last line is a bug. You've confused yourself by
calling your variable "file_path". It is not a path; it is a POSIX file. It
is already a way of specifying the file, so you cannot use it form an a file
specifier with the word "file". Notice the mismatch between how you specify
the file in the "open for access" and how you do it in the last line. Of
course the real solution is to close access open_file - once you have a file
number, just keep using it. Basically you've used so many ways of referring
to the file that you've confused the heck out of yourself. m.