Parsing entries in a log file

Hey Forum.

I need some help figuring this out. In my AppleScript application, I’ve integrated a logging component to log of all the files it has processed. The information written to a .txt file and each line contains a timestamp followed by a ‘tab’ and the file name. When the application begins working on a new batch of files, there’s an entry indicating a new batch has started. A sample log file follows below:

After the batch of files runs, I want to read the log and only pull the entries for the latest batch, then include that in an e-mail.
I’ve got to the point where I can read the log file and pull the entire contents of it into an AppleScript var as a list. The e-mail component is all set up and waiting to plug in a variable that contains the parsed list.

An example of how the entries from the last batch of the log should look – omitting the “Processing Start for Batch” message.

But I’m stuck on how to parse the list for just the last entries for last batch of files processed.

Any advise would be appreciated.


Model: MacPro / MacBook Pro
Browser: Safari 533.18.5
Operating System: Mac OS X (10.6)


could be like this .

--list entries of the logfile
set logentries to paragraphs of "2010 Nov 19 Fri 16:56:15    PROCESSING START FOR BATCH
2010 Nov 19 Fri 16:56:46    STP_GrilledPizza_01.psd
2010 Nov 19 Fri 16:57:10    STP_GrilledPizza_08.psd
2010 Nov 19 Fri 16:57:31    STP_GrilledPizza_18.psd
2010 Nov 19 Fri 17:31:07    PROCESSING START FOR BATCH
2010 Nov 19 Fri 17:31:12    SIL_StoringScallions_01.psd
2010 Nov 19 Fri 17:31:18    STP_CucumberSeedingII_02.psd
2010 Nov 19 Fri 17:31:23    STP_LegOfLamb_003.psd
2010 Nov 19 Fri 17:31:29    STP_LegOfLamb_005.psd
2010 Nov 19 Fri 17:31:34    STP_LegOfLamb_007.psd
2010 Nov 19 Fri 17:31:39    STP_LegOfLamb_010.psd
2010 Nov 19 Fri 17:31:44    STP_LegOfLamb_018.psd
2010 Nov 19 Fri 17:31:50    STP_LegOfLamb_020.psd
2010 Nov 19 Fri 17:31:56    STP_RoastPork_SaltSugarRub_64.psd
2010 Nov 22 Mon 11:24:21    PROCESSING START FOR BATCH
2010 Nov 22 Mon 11:24:34    STP_CarvingChicken - 1 of 4.psd
2010 Nov 22 Mon 11:24:39    STP_CarvingChicken - 2 of 4.psd
2010 Nov 22 Mon 11:24:45    STP_CarvingChicken - 3 of 4.psd
2010 Nov 22 Mon 11:24:50    STP_CarvingChicken - 4 of 4.psd
2010 Nov 22 Mon 14:24:08    PROCESSING START FOR BATCH
2010 Nov 22 Mon 14:25:14    SFS_beef_hand_pies_015.psd
2010 Nov 22 Mon 14:26:34    SFS_Chicken_Lettuce_Wraps_012.psd
2010 Nov 22 Mon 14:28:47    SFS_Lamb_Shwarma_014.psd
2010 Nov 22 Mon 14:29:12    STP_HandPies_03.psd
2010 Nov 22 Mon 14:29:29    STP_HandPies_08.psd
2010 Nov 22 Mon 14:29:54    STP_HandPies_11.psd
2010 Nov 22 Mon 14:30:14    STP_LambShaving_04.psd"

set lastEntries to {} --empty list for last entries
repeat with i from (count of logentries) to 1 by -1 --start repeating from the end of the log-list
	set theEntry to item i of logentries
	if theEntry does not contain "PROCESSING START FOR BATCH" then
		set beginning of lastEntries to theEntry
		set {TID, text item delimiters} to {text item delimiters, return}
		return lastEntries as text --returning the last batch as text
		set AppleScript's text item delimiters to TID
		exit repeat
	end if
end repeat