-- Script to read the system.log and show softRAID messages using GROWL. -- Make sure the system.log is readable by this application. -- Save this script from ScriptEditor as Application with checkbox "stay open" property useGrowl : true -- set this to true to get warnings via Growl (http://growl.info/) property updateDelay : 15 -- seconds property scriptName : "syslogSoftRAID" -- the name of this script property SoftRAIDAppName : "SoftRAID 3.6.app" -- the name of the softRAID application, to get its icon property softRAIDFilter : "SoftRAID driver" -- text to filter the syslog on property shownItems : {} -- list of lines that have already been processed/shown property useDelayLoop : false -- set this to true if you want to run from Script Editor property onlySoftRAIDLog : true -- set this to true if you want to see only SoftRAID property firstLookBackTime : hours * 2 -- how far back do we look the first time property normalLookBackTime : 5 * updateDelay -- how far back do we look normally property lookBackTime : firstLookBackTime -- the time to look back property firstReadBackLines : 1000 -- number of lines to read from syslog the first time property normalReadBackLines : 20 -- number of lines to read back normally property readBackLines : firstReadBackLines -- number of lines to read from syslog property maxMemoryLines : 1000 -- number of lines to hold in memory property firsttime : true -- if it is the first time we do this -- the run handler (invoked at script startup) on run --display dialog ("running") if useGrowl then registerWithGrowl() end if update() delay updateDelay if useDelayLoop then repeat update() delay updateDelay end repeat end if end run -- the idle handler (invoked every 'updateDelay' seconds) on idle if useDelayLoop then -- we should never get here display alert "Internal error: idle handler called even though using delay loop" quit end if update() return updateDelay end idle -- do the things we should do on update() set now to current date if onlySoftRAIDLog then set logLines to do shell script "grep '" & softRAIDFilter & "' /var/log/system.log |tail -n " & readBackLines else set logLines to do shell script "cat /var/log/system.log |tail -n " & readBackLines end if -- get the list of lines set myList to paragraphs of logLines -- check all lines we read repeat with anItem in myList set txt to anItem as string -- to make sure it is a normal string -- get the date of the line set datestr to word 1 of txt & space & word 2 of txt & "," & year of now set h to word 3 of txt set m to word 4 of txt set s to word 5 of txt set timestr to h & ":" & m & space & s set logdate to date (datestr & space & timestr) set timedifference to now - logdate -- seconds -- if it is not too old and not handled before, we can handle it if (timedifference < lookBackTime) and (shownItems does not contain anItem) then set txt to text (word 6) thru end of txt -- strip the timestamp set txt to text ((offset of ":" in txt) + 1) thru end of txt -- skip all until colon if (timedifference > normalLookBackTime) then -- if it is kinda old (the first time) we want to show the time set txt to h & ":" & m & ":" & s & " " & txt end if if txt contains softRAIDFilter then displaySoftRAIDWarningUsingGrowl(SoftRAIDAppName, txt) else displayOtherWarningUsingGrowl("Console", txt) end if -- remember this line to prevent it from being displayed more than once set end of shownItems to (anItem as string) -- prevent memory overflow by deleting old lines if memory is full enough if (count of shownItems) > maxMemoryLines then delete first item of shownItems end if end if end repeat if firsttime is true then -- this is the first time, set some properties to normal values set readBackLines to normalReadBackLines set lookBackTime to normalLookBackTime set firsttime to false end if end update -- display a message using Growl on displaySoftRAIDWarningUsingGrowl(appName, msg) tell application "GrowlHelperApp" notify with name "SoftRAID Driver system.log lines" title "SoftRAID" description msg application name scriptName icon of application appName end tell end displaySoftRAIDWarningUsingGrowl -- display a message using Growl on displayOtherWarningUsingGrowl(appName, msg) tell application "GrowlHelperApp" notify with name "non-SoftRAID system.log lines" title "system.log" description msg application name scriptName icon of application appName end tell end displayOtherWarningUsingGrowl -- registerWithGrowl: -- Registers our notifications with the "Growl" tool on registerWithGrowl() set notifList to {"SoftRAID Driver system.log lines", "non-SoftRAID system.log lines"} tell application "GrowlHelperApp" register as application scriptName all notifications notifList default notifications notifList end tell end registerWithGrowl