Using iCal 1.5 with Indigo
Posted: Tue Oct 21, 2003 9:06 pm
This is an attachement script that I use to log motion detector activity to iCal. I can go to my HA machine and see when there was activity and from what motion detector. To use you create a trigger and put this in the applescript area
Here is the code for the attachment
-------------------------
[This script was automatically tagged for color coded syntax by Script to Markup Code]
- Code: Select all
logical("The Motion Detector Name")
Here is the code for the attachment
--[url=applescript://com.apple.scripteditor/?action=new&script=property%20iCalendars%20%3A%20%7B%7D%0A%0Aset%20theCals%20to%20%7B%7D%0Aset%20iCalendars%20to%20%7B%7D%0A%0Ausing%20terms%20from%20application%20%22Indigo%22%0A%09on%20logiCal(unitname)%0A%09%09--Set%20the%20Calendar%20Name%20%0A%09%09set%20theCalName%20to%20unitname%0A%09%09set%20eventdate%20to%20current%20date%0A%09%09%0A%09%09--Get%20the%20Calendars%20from%20iCal%20%0A%09%09tell%20application%20%22iCal%22%0A%09%09%09set%20theCals%20to%20calendars%0A%09%09%09repeat%20with%20i%20from%201%20to%20count%20of%20theCals%0A%09%09%09%09copy%20title%20of%20item%20i%20of%20theCals%20to%20end%20of%20iCalendars%0A%09%09%09end%20repeat%0A%09%09%09%0A%09%09%09--%20If%20there%20is%20no%20calendar%20for%20this%20unit%20create%20one%20%0A%09%09%09if%20theCalName%20is%20not%20in%20iCalendars%20then%0A%09%09%09%09create%20calendar%20with%20name%20theCalName%0A%09%09%09%09--%20Refresh%20calendar%20list%20with%20our%20new%20one%CA%20%CA%CA%20%CA%20%0A%09%09%09%09set%20iCalendars%20to%20%7B%7D%0A%09%09%09%09set%20theCals%20to%20%7B%7D%0A%09%09%09%09set%20theCals%20to%20calendars%0A%09%09%09%09repeat%20with%20i%20from%201%20to%20count%20of%20theCals%0A%09%09%09%09%09copy%20title%20of%20item%20i%20of%20theCals%20to%20end%20of%20iCalendars%0A%09%09%09%09end%20repeat%0A%09%09%09end%20if%0A%09%09end%20tell%0A%09%09%0A%09%09--%20Run%20through%20our%20Calendar%20list%20and%20find%20the%20iCal%20id%20of%20theCalName%20%0A%09%09set%20i%20to%201%0A%09%09repeat%20with%20anitem%20in%20iCalendars%0A%09%09%09if%20item%20i%20of%20iCalendars%20is%20equal%20to%20theCalName%20then%0A%09%09%09%09set%20theNum%20to%20i%0A%09%09%09%09exit%20repeat%0A%09%09%09end%20if%0A%09%09%09set%20i%20to%20i%20+%201%0A%09%09end%20repeat%0A%09%09%0A%09%09set%20theSummary%20to%20%22Motion%20Detected%20at%22%20%26%20eventdate%20as%20string%0A%09%09%0A%09%09tell%20application%20%22iCal%22%0A%09%09%09make%20event%20at%20end%20of%20events%20of%20calendar%20theNum%20with%20properties%20%7Bstart%20date%3Aeventdate,%20summary%3AtheSummary%7D%0A%09%09end%20tell%0A%09end%20logiCal%0Aend%20using%20terms%20from%0A]Click here to open this script in a new Script Editor window[/url].
property iCalendars : {}
set theCals to {}
set iCalendars to {}
using terms from application "Indigo"
on logiCal(unitname)
--Set the Calendar Name
set theCalName to unitname
set eventdate to current date
--Get the Calendars from iCal
tell application "iCal"
set theCals to calendars
repeat with i from 1 to count of theCals
copy title of item i of theCals to end of iCalendars
end repeat
-- If there is no calendar for this unit create one
if theCalName is not in iCalendars then
create calendar with name theCalName
-- Refresh calendar list with our new one
set iCalendars to {}
set theCals to {}
set theCals to calendars
repeat with i from 1 to count of theCals
copy title of item i of theCals to end of iCalendars
end repeat
end if
end tell
-- Run through our Calendar list and find the iCal id of theCalName
set i to 1
repeat with anitem in iCalendars
if item i of iCalendars is equal to theCalName then
set theNum to i
exit repeat
end if
set i to i + 1
end repeat
set theSummary to "Motion Detected at" & eventdate as string
tell application "iCal"
make event at end of events of calendar theNum with properties {start date:eventdate, summary:theSummary}
end tell
end logiCal
end using terms from
-------------------------
[This script was automatically tagged for color coded syntax by Script to Markup Code]