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: problem writing out XML suite parsed file to disk



There's a couple of things that stand out.

Why is the write command within a System Events tell? It's from the Standard Additions osax and has nothing to do with System Events.

The try block will not close the file if it throws an error. You've left out the "on error" portion so the block just ignores any errors. This is fine if you don't need to handle errors but in this case you do!

This script is written with the assumption that "thePodcast" is textual in nature and not audio or video.

--> Script <--
set fPath to "the:path:to:your:file" as Unicode text
try
set fRef to open for access file fPath with write permission
set eof fRef to 0 -- not necessary if new file
write thePodcast to fRef as text starting at 0
close access fRef
on error errMsg number errNum
close access file fPath
display alert ("Error # " & errNum) message errMsg buttons {"Cancel"} giving up after 5
-- your error handler code goes here
end try
--> /Script <--

JBS

JBS,

thanks for your input - I now have it working! I did have on error handling already within the try/end try block, but separating out getting the text from the thePodcast object, which uses XML suite (which is why it was in the System Events tell block), from the actual writing of the file did the trick. The working script now looks like:

<script>

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_pointer to POSIX file posixPath

try
set the open_file to open for access file_pointer with write permission
set eof of the open_file to 0
tell application "System Events"
set podcastText to text of thePodcast
end tell
write podcastText to open_file starting at eof
close access open_file
on error error_message number error_number
close access open_file
display dialog "An error was encountered writing the file to: " & open_file & ". Error: " & error_message
end try

</script>

Thanks!

Will




 _______________________________________________
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

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.