The Omni Group Forums

The Omni Group Forums (http://forums.omnigroup.com/index.php)
-   OmniFocus Extras (http://forums.omnigroup.com/forumdisplay.php?f=44)
-   -   Setting nested context from script (http://forums.omnigroup.com/showthread.php?t=4492)

donhoffman 2007-08-10 02:40 PM

Setting nested context from script
 
Are there any examples of how to set a nested context from the scripting interface? E.g., Work->Email

Thanks,
Don

RobTrew 2007-08-13 01:42 PM

You need a reference to the corresponding element in the contexts tree of the document

One way would be something like:

[CODE]tell application "OmniFocus"

set oContextList to contexts of first document

set oContext to my FindContext("Email", oContextList)

-- ...
-- Assume creation of, or reference to an Omnifocus task (oTask) somewhere here
-- ...

set context of oTask to oContext

end tell


-- get a pointer to any defined context with this name
on FindContext(strName, oContexts)
tell application "OmniFocus"
ignoring case
repeat with oContext in oContexts
-- set strContextName to name of oContext
if (name of oContext) = strName then
return oContext
else
set oSubContexts to contexts of oContext
if (count of (oSubContexts)) > 0 then
set ContextFound to my FindContext(strName, oSubContexts)
-- Check whether a context has in fact been found
try
set SomeName to name of ContextFound
return ContextFound
end try
end if
end if
end repeat
end ignoring
end tell
end FindContext[/CODE]

RobTrew 2007-08-14 01:43 AM

Or, quicker ...
 
Probably quicker, in fact, to use the verb "Complete" which is provided in the Omnifocus applescript dictionary, and which will find nested contexts directly.

[CODE]tell application "OmniFocus"
tell first document
set oTask to make new inbox task with properties {name:"Testing"}

try
set context of oTask to my FindContext("Email")
end try
end tell
end tell


on FindContext(strContext)
tell application "OmniFocus"
tell first document
set oContextList to complete strContext as context maximum matches 1
if (oContextList is {}) then
else
return context id (id of item 1 of oContextList)
end if
end tell
end tell
end FindContext
[/CODE]

RobTrew 2007-08-14 02:54 AM

Finally, if you had two nested contexts with the same name, e.g.
[INDENT]Work > Email[/INDENT]and[INDENT]Home > Email[/INDENT]
you could specify the particular path by using a colon as a separator.
For example, using the FindContext() function defined in the previous post:

[CODE]try
set context of oTask to my FindContext("Work:Email")
end try[/CODE]

menza 2011-09-16 12:22 PM

Adding a task with nested contexts
 
I would like to use Applescript to add a task with nested contexts (a task with the context people:keith). I have been unable to discover how to do this.

Any help would be appreciated.

Brian 2011-09-16 01:48 PM

Menza, I'm going to move your post to an existing thread which has the info you're looking for. Responding in the thread you created before I do that so you get any notifications you signed up for.


All times are GMT -8. The time now is 08:55 PM.

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