|
|
version?
Hi
linewrapping
I think that when you download the script, it adds some linefeeds which messes up the script. Here is a better version:
-- 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 * 10 -- 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
if logLines is equal to "" then
display dialog ("read my rights")
quit
end if
-- get the list of lines
set myList to paragraphs of logLines
-- check all lines we read
repeat with anItem in myList
set now to current date
set txt to anItem as string -- to make sure it is a normal string
if txt is not equal to "" then
set m to word 1 of txt
set d to word 2 of txt
set y to year of now
if (month of now as string) contains m then
--display dialog ("month of now as string [" & (month of now as string) & "] contains m[" & m & "]")
set m to month of now
else
--display dialog ("month of now as string [" & (month of now as string) & "] does not contains m[" & m & "]")
set tempdate to now
set day of tempdate to 1
set prevmonth to tempdate - 1 * days
set m to month of prevmonth
set y to year of prevmonth
--display dialog (prevmonth as string)
--display dialog ("m=" & m & " y=" & y)
--display dialog (now as string)
end if
set logdate to date (now as string)
--display dialog (now as string)
set day of logdate to d
set month of logdate to m
set year of logdate to y
--display dialog (now as string)
set h to word 3 of txt
set m to word 4 of txt
set s to word 5 of txt
set hours of logdate to h
set minutes of logdate to m
set seconds of logdate to s
--display dialog (now as string)
--displayOtherWarningUsingGrowl("time", logdate as string)
set timedifference to now - logdate -- seconds
-- if it is not too old and not handled before, we can handle it
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)
--display dialog (timedifference)
displaySoftRAIDWarningUsingGrowl(SoftRAIDAppName, (logdate as string) & 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 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
|
SearchFrom our Sponsor...Latest Mountain Lion HintsWhat's New:HintsNo new hintsComments last 2 daysNo new commentsLinks last 2 weeksNo recent new linksWhat's New in the Forums?
Hints by TopicNews from Macworld
From Our Sponsors |
|
Copyright © 2014 IDG Consumer & SMB (Privacy Policy) Contact Us All trademarks and copyrights on this page are owned by their respective owners. |
Visit other IDG sites: |
|
|
|
Created this page in 0.08 seconds |
|