daily pastebin goal

Applescript filewrite

a guest Nov 16th, 2011 181 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. do shell script "/Users/Nick/Dropbox/Untitled.command"
  2. set theFile to "/Users/Nick/Documents/values.txt"
  3. open for access theFile
  4. set fileContents to (read theFile)
  5. close access theFile
  7. set costItems to {}
  8. set x to 1
  9. tell application "System Events"
  10.         set XMLRoot to make new XML data with data fileContents
  11.         repeat with searchItems in (XML elements of XML element "searchResult" of XML element "findItemsAdvancedResponse" of XMLRoot)
  12.                 set end of costItems to value of XML element "convertedCurrentPrice" of XML element "sellingStatus" of searchItems
  13.                 if x is not 5 then
  14.                         set x to x + 1
  15.                 else
  16.                         exit repeat
  17.                 end if
  18.         end repeat
  19. end tell
  20. return costItems
  22. tell application "Finder"
  23.         try
  24.                 set the_file to "/Users/Nick/Documents/outputvals.txt" as POSIX file as alias
  25.         on error --file doesn't exist yet, so create it
  26.                 set the_file to (make new document file at ("/Users/Nick/Documents/" as POSIX file as alias) with properties {name:"outputvals", text:""})
  27.                 --Normally, when you're creating documents in this fashion, you would put the text you want in the document after the 'text' property, but for your sake I will use the alternative :)
  28.         end try
  29. end tell
  30. set the_data to costItems
  31. try
  32.         open for access the_file with write permission
  33.         write the_data to file the_file starting at eof
  34.         close access the_file
  35. on error --you never know when errors will crop up (when it comes to reading and writing files); better to be safe than sorry
  36.         try
  37.                 close access the_file
  38.         end try
  39. end try
RAW Paste Data