Here's the latest incarnation of my iCal logging script. I've changed it quite a bit.
There's two ways to use it.
1) Use LogDevice(DeviceName) for devices.
2) Use logmessages(MessageGroup, message, EventKind) for non devices.
You set EventKind to true for the start of an event and EventKind to false for the end of a event. Or if you want to just do a single logging use false for EventKind.
This version makes use of the built in iCal properties and filters out Motion Detectors.
Note: I use the description field pretty heavily and this script may require that you have the proper info there.
--[url=applescript://com.apple.scripteditor/?action=new&script=using%20terms%20from%20application%20%22Indigo%22%0A%09on%20logmessages(MessageGroup,%20message,%20EventKind)%0A%09%09set%20MinSummaryLength%20to%205%0A%09%09set%20theLocation%20to%20%22Message%22%0A%09%09set%20eventdate%20to%20current%20date%0A%09%09if%20MessageGroup%20contains%20%22Messages%22%20then%20set%20EventKind%20to%20false%0A%09%09%0A%09%09set%20OldDelims%20to%20AppleScript's%20text%20item%20delimiters%0A%09%09set%20AppleScript's%20text%20item%20delimiters%20to%20%22%20%22%0A%09%09set%20theList%20to%20the%20text%20items%20of%20message%0A%09%09set%20AppleScript's%20text%20item%20delimiters%20to%20OldDelims%0A%09%09set%20x%20to%20count%20of%20items%20in%20theList%0A%09%09if%20x%20is%20greater%20than%20MinSummaryLength%20then%0A%09%09%09set%20i%20to%200%0A%09%09%09repeat%20with%20n%20from%201%20to%20x%0A%09%09%09%09set%20i%20to%20i%20+%201%0A%09%09%09%09if%20i%20is%201%20then%0A%09%09%09%09%09set%20LogTemp%20to%20item%20i%20of%20theList%0A%09%09%09%09else%0A%09%09%09%09%09set%20LogTemp%20to%20LogTemp%20%26%20%22%20%22%20%26%20item%20i%20of%20theList%0A%09%09%09%09end%20if%0A%09%09%09%09if%20i%20is%20MinSummaryLength%20then%20exit%20repeat%0A%09%09%09end%20repeat%0A%09%09%09set%20LogTemp%20to%20LogTemp%20%26%20%22...%22%0A%09%09else%0A%09%09%09set%20LogTemp%20to%20message%0A%09%09end%20if%0A%09%09LogIniCal(MessageGroup,%20LogTemp,%20message,%20theLocation,%20eventdate,%20EventKind)%0A%09end%20logmessages%0A%09%0A%09on%20LogDevice(DeviceName)%0A%09%09tell%20application%20%22Indigo%22%0A%09%09%09log%20%22Log%20Device%3A%20%22%20%26%20DeviceName%0A%09%09%09if%20(name%20of%20device%20DeviceName%20exists)%20then%0A%09%09%09%09set%20HouseMode%20to%20(value%20of%20variable%20%22HouseMode%22)%0A%09%09%09%09set%20eventdate%20to%20current%20date%0A%09%09%09%09--Device%20Info%0A%09%09%09%09set%20UnitDisc%20to%20description%20of%20device%20DeviceName%0A%09%09%09%09set%20unitstate%20to%20on%20state%20of%20device%20DeviceName%0A%09%09%09%09set%20UnitType%20to%20type%20of%20device%20DeviceName%0A%09%09%09%09set%20LogExtended%20to%20%22%22%0A%09%09%09%09set%20theLocation%20to%20UnitType%20%26%20%22%20%22%20%26%20UnitDisc%0A%09%09%09%09%0A%09%09%09%09if%20UnitType%20is%20%22Motion%20Detectors%22%20or%20unitstate%20is%20false%20then%0A%09%09%09%09%09set%20EventKind%20to%20false%0A%09%09%09%09else%0A%09%09%09%09%09set%20EventKind%20to%20true%0A%09%09%09%09end%20if%0A%09%09%09%09%0A%09%09%09%09--Send%20out%20LanOSD%20broadcast%20regardless%20of%20house%20state%20if%20there%20is%20an%20outside%20motion%20detector%20triggered%0A%09%09%09%09if%20UnitType%20is%20%22Motion%20Detector%22%20and%20UnitDisc%20contains%20%22outdoor%22%20then%0A%09%09%09%09%09try%0A%09%09%09%09%09%09tell%20application%20%22LanOSD%22%0A%09%09%09%09%09%09%09message%20kind%20UnitType%20text%20UnitType%20%26%20%22%22%20%26%20UnitDisc%20icon%20%22warning%22%20quadrant%208%20fade%20delay%204%0A%09%09%09%09%09%09end%20tell%0A%09%09%09%09%09end%20try%0A%09%09%09%09end%20if%0A%09%09%09%09(*%20log%20%22HouseMode%3A%20%22%20%26%20HouseMode%0A%09%09%09%09log%20%22eventdate%3A%20%22%20%26%20eventdate%0A%09%09%09%09log%20%22UnitDisc%3A%20%22%20%26%20UnitDisc%0A%09%09%09%09log%20%22unitstate%3A%20%22%20%26%20unitstate%0A%09%09%09%09log%20%22UnitType%3A%20%22%20%26%20UnitType%0A%09%09%09%09log%20%22LogExtended%3A%20%22%20%26%20LogExtended%0A%09%09%09%09log%20%22theLocation%3A%20%22%20%26%20theLocation%20*)%0A%09%09%09%09if%20UnitType%20is%20%22Motion%20Detector%22%20and%20HouseMode%20is%20%22away%22%20then%20LogIniCal(UnitType,%20DeviceName,%20LogExtended,%20theLocation,%20eventdate,%20EventKind)%0A%09%09%09%09if%20UnitType%20is%20not%20%22Motion%20Detector%22%20and%20UnitDisc%20does%20not%20contain%20%22RCS%22%20then%20LogIniCal(UnitType,%20DeviceName,%20LogExtended,%20theLocation,%20eventdate,%20EventKind)%0A%09%09%09end%20if%0A%09%09end%20tell%0A%09end%20LogDevice%0A%09%0A%09on%20LogIniCal(theCalName,%20theSummary,%20theNote,%20theLocation,%20eventdate,%20EventKind)%0A%09%09tell%20application%20%22iCal%22%0A%09%09%09--Get%20the%20Calendars%20from%20iCal%0A%09%09%09repeat%0A%09%09%09%09set%20i%20to%200%0A%09%09%09%09set%20theCalID%20to%200%0A%09%09%09%09repeat%20with%20CurrentCal%20in%20calendars%0A%09%09%09%09%09set%20i%20to%20i%20+%201%0A%09%09%09%09%09if%20title%20of%20CurrentCal%20is%20theCalName%20then%0A%09%09%09%09%09%09set%20theCalID%20to%20i%0A%09%09%09%09%09%09exit%20repeat%0A%09%09%09%09%09end%20if%0A%09%09%09%09end%20repeat%0A%09%09%09%09if%20theCalID%20is%20not%200%20then%0A%09%09%09%09%09exit%20repeat%0A%09%09%09%09else%0A%09%09%09%09%09create%20calendar%20with%20name%20theCalName%0A%09%09%09%09end%20if%0A%09%09%09end%20repeat%0A%0A%09%09%09set%20CompletedEvent%20to%20false%0A%09%09%09set%20EventCount%20to%20count%20of%20(events%20of%20calendar%20theCalID)%0A%09%09%09set%20i%20to%200%0A%09%09%09repeat%20with%20theevent%20in%20(events%20of%20calendar%20theCalID)%0A%09%09%09%09set%20i%20to%20i%20+%201%0A%09%09%09%09if%20summary%20of%20theevent%20is%20(theSummary)%20and%20EventKind%20is%20true%20and%20status%20of%20theevent%20is%20tentative%20and%20(start%20date)%20of%20theevent%20is%20(end%20date)%20of%20theevent%20then%0A%09%09%09%09%09--weve%20got%20an%20extra%20event%20that%20hasn't%20been%20closed%20off.%20Fix%20it%0A%09%09%09%09%09set%20summary%20of%20theevent%20to%20theSummary%0A%09%09%09%09%09--set%20(end%20date%20of%20theevent)%20to%20(start%20date%20of%20theevent)%0A%09%09%09%09%09set%20status%20of%20theevent%20to%20cancelled%0A%09%09%09%09%09set%20note%20of%20theevent%20to%20%22Unclosed%20event%20found,%20closing%20with%20unknown%20end%20date%22%0A%09%09%09%09else%20if%20summary%20of%20theevent%20is%20(theSummary)%20and%20EventKind%20is%20false%20and%20status%20of%20theevent%20is%20tentative%20and%20(start%20date)%20of%20theevent%20is%20(end%20date)%20of%20theevent%20then%0A%09%09%09%09%09--This%20is%20the%20last%20event%20that%20needs%20closed%0A%09%09%09%09%09set%20summary%20of%20theevent%20to%20theSummary%0A%09%09%09%09%09set%20(end%20date%20of%20theevent)%20to%20eventdate%0A%09%09%09%09%09set%20note%20of%20theevent%20to%20theNote%0A%09%09%09%09%09set%20status%20of%20theevent%20to%20confirmed%0A%09%09%09%09%09set%20CompletedEvent%20to%20true%0A%09%09%09%09end%20if%0A%09%09%09end%20repeat%0A%09%09%09if%20EventKind%20is%20true%20then%0A%09%09%09%09--Make%20new%20started%20event%0A%09%09%09%09make%20event%20at%20end%20of%20events%20of%20calendar%20theCalID%20with%20properties%20%7Bstart%20date%3Aeventdate,%20summary%3AtheSummary,%20description%3AtheNote,%20location%3AtheLocation,%20status%3Atentative%7D%0A%09%09%09else%20if%20CompletedEvent%20is%20false%20and%20EventKind%20is%20false%20then%0A%09%09%09%09make%20event%20at%20end%20of%20events%20of%20calendar%20theCalID%20with%20properties%20%7Bstart%20date%3Aeventdate,%20summary%3AtheSummary,%20description%3AtheNote,%20location%3AtheLocation,%20status%3Aconfirmed%7D%0A%09%09%09end%20if%0A%09%09end%20tell%0A%09end%20LogIniCal%0Aend%20using%20terms%20from%0A]Click here to open this script in a new Script Editor window[/url].
using terms from application "Indigo"
on logmessages(MessageGroup, message, EventKind)
set MinSummaryLength to 5
set theLocation to "Message"
set eventdate to current date
if MessageGroup contains "Messages" then set EventKind to false
set OldDelims to AppleScript's text item delimiters
set AppleScript's text item delimiters to " "
set theList to the text items of message
set AppleScript's text item delimiters to OldDelims
set x to count of items in theList
if x is greater than MinSummaryLength then
set i to 0
repeat with n from 1 to x
set i to i + 1
if i is 1 then
set LogTemp to item i of theList
else
set LogTemp to LogTemp & " " & item i of theList
end if
if i is MinSummaryLength then exit repeat
end repeat
set LogTemp to LogTemp & "..."
else
set LogTemp to message
end if
LogIniCal(MessageGroup, LogTemp, message, theLocation, eventdate, EventKind)
end logmessages
on LogDevice(DeviceName)
tell application "Indigo"
log "Log Device: " & DeviceName
if (name of device DeviceName exists) then
set HouseMode to (value of variable "HouseMode")
set eventdate to current date
--Device Info
set UnitDisc to description of device DeviceName
set unitstate to on state of device DeviceName
set UnitType to type of device DeviceName
set LogExtended to ""
set theLocation to UnitType & " " & UnitDisc
if UnitType is "Motion Detectors" or unitstate is false then
set EventKind to false
else
set EventKind to true
end if
--Send out LanOSD broadcast regardless of house state if there is an outside motion detector triggered
if UnitType is "Motion Detector" and UnitDisc contains "outdoor" then
try
tell application "LanOSD"
message kind UnitType text UnitType & "" & UnitDisc icon "warning" quadrant 8 fade delay 4
end tell
end try
end if
(* log "HouseMode: " & HouseMode
log "eventdate: " & eventdate
log "UnitDisc: " & UnitDisc
log "unitstate: " & unitstate
log "UnitType: " & UnitType
log "LogExtended: " & LogExtended
log "theLocation: " & theLocation *)
if UnitType is "Motion Detector" and HouseMode is "away" then LogIniCal(UnitType, DeviceName, LogExtended, theLocation, eventdate, EventKind)
if UnitType is not "Motion Detector" and UnitDisc does not contain "RCS" then LogIniCal(UnitType, DeviceName, LogExtended, theLocation, eventdate, EventKind)
end if
end tell
end LogDevice
on LogIniCal(theCalName, theSummary, theNote, theLocation, eventdate, EventKind)
tell application "iCal"
--Get the Calendars from iCal
repeat
set i to 0
set theCalID to 0
repeat with CurrentCal in calendars
set i to i + 1
if title of CurrentCal is theCalName then
set theCalID to i
exit repeat
end if
end repeat
if theCalID is not 0 then
exit repeat
else
create calendar with name theCalName
end if
end repeat
set CompletedEvent to false
set EventCount to count of (events of calendar theCalID)
set i to 0
repeat with theevent in (events of calendar theCalID)
set i to i + 1
if summary of theevent is (theSummary) and EventKind is true and status of theevent is tentative and (start date) of theevent is (end date) of theevent then
--weve got an extra event that hasn't been closed off. Fix it
set summary of theevent to theSummary
--set (end date of theevent) to (start date of theevent)
set status of theevent to cancelled
set note of theevent to "Unclosed event found, closing with unknown end date"
else if summary of theevent is (theSummary) and EventKind is false and status of theevent is tentative and (start date) of theevent is (end date) of theevent then
--This is the last event that needs closed
set summary of theevent to theSummary
set (end date of theevent) to eventdate
set note of theevent to theNote
set status of theevent to confirmed
set CompletedEvent to true
end if
end repeat
if EventKind is true then
--Make new started event
make event at end of events of calendar theCalID with properties {start date:eventdate, summary:theSummary, description:theNote, location:theLocation, status:tentative}
else if CompletedEvent is false and EventKind is false then
make event at end of events of calendar theCalID with properties {start date:eventdate, summary:theSummary, description:theNote, location:theLocation, status:confirmed}
end if
end tell
end LogIniCal
end using terms from
-------------------------
[This script was automatically tagged for color coded syntax by
Script to Markup Code]