The Omni Group
These forums are now read-only. Please visit our new forums to participate in discussion. A new account will be required to post in the new forums. For more info on the switch, see this post. Thank you!

Go Back   The Omni Group Forums > OmniFocus > OmniFocus Extras
FAQ Members List Calendar Search Today's Posts Mark Forums Read

AppleScript to add tasks in a particular context to iCal for notifications Thread Tools Search this Thread Display Modes
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.

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
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

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.

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
Thread Thread Starter Forum Replies Last Post
Script: Export (from an 'iCal' context) to iCal RobTrew OmniFocus Extras 0 2012-04-10 07:21 AM
iCal Sync - 1 Context -> 2 iCal Calendars visionsnap OmniFocus 1 for Mac 3 2010-01-16 07:00 PM
Why calendar notifications instead of Push notifications? Brian OmniFocus for iPhone 25 2009-07-22 03:01 PM
Applescript Snippet Request: Get Tasks for Context kenclark OmniFocus Extras 2 2009-02-12 02:46 AM
Inability to Sync iCal Tasks w/out Context supafly iCal Sync 1 2007-08-19 07:19 AM

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

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