• 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
Re: problem writing out XML suite parsed file to disk
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: problem writing out XML suite parsed file to disk


  • Subject: Re: problem writing out XML suite parsed file to disk
  • From: email@hidden
  • Date: Thu, 27 Apr 2006 08:56:13 +0100

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:

This email sent to email@hidden

  • Prev by Date: Re: scripting Word top copy text - should be simple, but ain't
  • Next by Date: ASR Error
  • Previous by thread: Re: problem writing out XML suite parsed file to disk
  • Next by thread: [Newbie] Scripting IB
  • Index(es):
    • Date
    • Thread