Ok this is starting to get a bit unwieldy to post to the list so I also put a copy in my dropbox folder at http://dl.dropbox.com/u/13002668/DropFile.scpt
In addition to what it did before this will save the serial number and validation code to a file 'FailedBatterySerialNumbers.txt' on your Desktop. I added the name of the file that the serial number came from. Figured you might want to go back and reference the original file.
The file looks like:
Untitled 2.txt
serial-number 4H6230BBVTH
Battery Validation Code NBD-75B1770F-02
Untitled 2.txt
serial-number 4H6230BBVTH
Battery Validation Code NBD-75B1770F-02
enjoy, regards
on opendroppedFiles
-- Set destination Folder on Desktop
set destDir to (path to desktop) as text
set destDir to alias (destDir & "FailedBatteries:")
-- Set string to search for in log files
set grepString to "failed"
-- For each file dropped on us look for the grepString
-- If found move the file to the destDir
repeat with aFile in the droppedFiles
try
set ret to do shell script "grep -i " & grepString & " " & quoted form of POSIX path of aFile
tell application "Finder" to moveaFiletodestDir
saveData(aFile)
on error msg number num
if num ≠ 1 then
display dialog "Unknow errror: " & msg & " Number:" & num & " in file:" & aFile
else
display dialog "KGB:" & grepString & " not found in file:" & return & aFile
end if
end try
end repeat
end open
on saveData(aFile)
try
set values to do shell script "grep -E '^serial-number|^Battery Validation Code' " & quoted form of POSIX path of aFile
on error msg number num
if num ≠ 1 then
display dialog "saveData:unknow errror: " & msg & " Number:" & num & " in file:" & aFile
else
display dialog "saveData: string not found in file:" & return & aFile
return
end if
end try
tell application "Finder" to set aFile to (name of aFile)
set fileName to (path to desktop as text) & "FailedBatterySerialNumbers.txt"
try
set fnum to open for accessfileName with write permission
on error msg number num
close accessfilefileName
display dialog "File error:" & msg & " number:" & num
return
end try
set ourEof to get eof of fnum
write (aFile & return & values & return & return) to fnum starting at ourEof + 1
close accessfilefileName
return
end saveData