Re: Monitoring the activity of a text file via AS
Re: Monitoring the activity of a text file via AS
- Subject: Re: Monitoring the activity of a text file via AS
- From: Nigel Smith <email@hidden>
- Date: Tue, 01 Jun 2004 13:34:36 +0100
On 31/5/04 4:22, "Richard Covert" <email@hidden> wrote:
>
I have a 'do shell script' which starts a UNIX program that reports
>
progress via stdout/stderr.
>
I can redirect stdout/stderr to a text file at any folder that I wish.
>
>
If I redirect the progress file to a Mac OS X folder then I can read
>
the file via my AS script. My question is
>
how do I read the tail of the file via AS?
>
>
I would like to echo the file to my text view object as the file is
>
being written to by my UNIX
>
program.
>
>
UNIX allows you to monitor the end of a file by doing a 'tail -f
>
<file>'.
So you know "do shell script", and you know "tail".
What's stopping you (apart from the delay involved in "do shell script")
from getting the last line with:
do shell script "tail -1 <file>"
If you want to go AS-only, how about:
set theVar to last paragraph of (read file <file>)
Note that the second option may not work, giving you an empty string,
depending on where your file comes from. You may have to get the
last-but-one paragraph instead:
set theVar to paragraph -2 of (read file <file>)
Or cover both possibilities with:
try
set theVar to paragraphs -2 thru -1 of (read file <file>)
if item 2 of theVar = "" then
set theVar to item 1 of theVar
else
set theVar to item 2 of theVar
end if
on error
try
set theVar to last paragraph of (read file <file>)
on error
--some other error to catch
end
end
HTH,
Nigel
_______________________________________________
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.