The Omni Group Forums

The Omni Group Forums (http://forums.omnigroup.com/index.php)
-   OmniFocus Extras (http://forums.omnigroup.com/forumdisplay.php?f=44)
-   -   AppleScript to add tasks in a particular context to iCal for notifications (http://forums.omnigroup.com/showthread.php?t=11003)

dmcg 2009-01-08 03:20 PM

AppleScript to add tasks in a particular context to iCal for notifications
 
So here's the scenario - there are things that I need to remember to collect before I leave the house. I always check my computer before I leave, but not necessarily OF.

So I've now set up a context "For Work". I run the following script at 1pm every morning (using iCal's script running), and it takes any tasks in that context and creates iCal todos for them with alarms. So when I come to my Mac, there are alert boxes for the things I need to take to work.

The script assumes you have a calendar named "Reminders", a context called "for work" and want reminding at 7am. I hope that it should be obvious what to edit to change these.

[FONT="Courier New"]
set morningContextName to "for work"
tell application "iCal"
set morningContextCalendar to calendar "Reminders"
end tell
set morningContextTime to 7 * 3600

tell application "OmniFocus"
my onContexts(contexts of default document)
end tell

on onContexts(contextList)
repeat with aContext in contextList
my onContext(aContext)
end repeat
end onContexts

on onContext(aContext)
using terms from application "OmniFocus"
set contextName to name of aContext
my onContexts(contexts of aContext)
my onTasks(tasks of aContext)
end using terms from
end onContext

on onTasks(TaskList)
repeat with aTask in TaskList
my onTask(aTask)
end repeat
end onTasks

on onTask(aTask)
using terms from application "OmniFocus"
set theContext to context of aTask
if theContext is not missing value then
set contextName to name of theContext
else
set contextName to missing value
end if
if aTask is not completed and contextName is equal to my morningContextName then
createTodo(name of aTask)
end if
end using terms from
end onTask

on createTodo(aSummary)
tell application "iCal"
set newtodo to (make new todo at end of my morningContextCalendar)
tell newtodo
set summary to aSummary
set alarmTime to my nextAlarmTime(my morningContextTime)
set due date to alarmTime
make new sound alarm at end with properties {trigger date:alarmTime}
end tell
end tell
end createTodo

on nextAlarmTime(timeSecs)
set now to current date
set alarmDay to now
if time of now is greater than my morningContextTime then
set day of alarmDay to (day of alarmDay) + 1
end if
set time of alarmDay to timeSecs
return alarmDay
end nextAlarmTime[/FONT]

I hope that either it is useful, or maybe the code to iterate over all tasks by context. I may revise it to create events, so that after a sync my iPhone is able to chime in to remind me.


All times are GMT -8. The time now is 01:31 PM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.