Created
May 3, 2011 08:57
-
-
Save thpani/953037 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### CONFIGURATION ### | |
global theTodoCalendar, theEventCalendar, eventPrefix | |
set theTodoCalendar to "Uni To Do" | |
set theEventCalendar to "Uni" | |
set eventPrefix to "DUE: " | |
### PROGRAM, don't modify! ### | |
to joinList(aList) | |
set retVal to "" | |
tell application "iCal" | |
repeat with theEvent in aList | |
set retVal to retVal & "\n- " & theEvent's start date | |
end repeat | |
end tell | |
end joinList | |
to getEvents(aSummary) | |
tell application "iCal" | |
tell calendar theEventCalendar | |
return every event whose summary is equal to eventPrefix & aSummary | |
end tell | |
end tell | |
end getEvents | |
tell application "iCal" | |
tell calendar theTodoCalendar | |
repeat with theTodo in every todo | |
set theEventsList to my getEvents(theTodo's summary) | |
set numEvents to theEventsList's length | |
if numEvents = 0 then | |
# no matching event found | |
if theTodo's due date is not missing value and theTodo's completion date is missing value then | |
set dueDate to theTodo's due date | |
display alert "Creating event for todo '" & theTodo's summary & "' on " & dueDate's short date string & "." | |
tell application "iCal" | |
tell calendar theEventCalendar | |
make new event at end with properties {summary:eventPrefix & theTodo's summary, start date:dueDate, allday event:true, url:"mailitem:" & theTodo's uid & "?type=todo&action=showparent"} | |
end tell | |
end tell | |
end if | |
else if numEvents = 1 then | |
# found a matching event | |
if theTodo's due date is not missing value and theTodo's completion date is not missing value then | |
display alert "Deleting event for completed todo '" & theTodo's summary & "'." | |
set theEvent to item 1 of theEventsList | |
tell application "iCal" | |
tell calendar theEventCalendar | |
delete theEvent | |
end tell | |
end tell | |
end if | |
else | |
# more than one matching event found | |
display alert "WUAAAA!!!\nFound more than one event for todo '" & theTodo's summary & "':" & my joinList(theEventsList) | |
end if | |
end repeat | |
end tell | |
end tell |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment