• 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: reading and deleting lines from a file
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: reading and deleting lines from a file


  • Subject: Re: reading and deleting lines from a file
  • From: kai <email@hidden>
  • Date: Fri, 22 Aug 2003 04:26:59 +0100

on Thu, 21 Aug 2003 10:30:43 -0700, Michael Glasser <email@hidden>
wrote:

> I am working on an AppleScript that, in part, needs to:
> 1) see if file "data" exist on desktop
> 2) if so, look to see if there is data in the file, if not, wait a
> couple seconds and try again
> 3) if there is data, read the first line and remove it from the data
> file
> 4) process the data...
> 5) return to step 1 (or maybe 2)
>
> I have been tinkering for a while, but can not get my prog to read one
> line at a time (read paragraph 1 seems to read the whole file), nor can
> I get it to delete the text that is being processed.
>
> The data file will be getting updated from elsewhere, which is why I
> need to keep checking...

Not sure if it's exactly what you want, Michael - but his works for me:

===========================================

set f to "Macintosh HD:Desktop Folder:data"
try
alias f
on error
display dialog "No data file." buttons {"Cancel"}
end try
repeat
repeat until (get eof f) > 0
delay 2
end repeat
set {p, r} to (paragraphs in (read file f))'s {item 1, rest}
set {d, text item delimiters} to {text item delimiters, return}
set eof f to 0
write (r as string) to f
set text item delimiters to d
display dialog "Ready to process: \"" & p & "\""
end repeat

===========================================

> If, for some reason, this is not possible, it would also be OK to read
> the whole file, delete all read lines, then process it one line at a
> time in a repeat loop... hmmm... that may be faster...

===========================================

set f to "Macintosh HD:Desktop Folder:data"
try
alias f
on error
display dialog "No data file." buttons {"Cancel"}
end try
repeat until (get eof f) > 0
delay 2
end repeat
set t to (read file f)'s paragraphs
set eof f to 0
repeat with p in t
display dialog "Ready to process: \"" & p & "\""
end repeat

===========================================

(If you have a very large data file, it may be necessary to process it in
chunks, but try the above first.)

---
kai
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.

  • Prev by Date: Who unsubscribed me AGAIN?
  • Next by Date: Re: reading and deleting lines from a file
  • Previous by thread: reading and deleting lines from a file
  • Next by thread: Re: reading and deleting lines from a file
  • Index(es):
    • Date
    • Thread