Quote:
Originally Posted by curt.clifton
Code:
on findContextNamed(theContexts, contextName)
if (theContexts is {}) then return missing value
set firstContext to item 1 of theContexts
using terms from application "OmniFocus"
if (name of firstContext is contextName) then return firstContext
set subContext to my findContextNamed(every context of firstContext, contextName)
if (subContext is not missing value) then return subContext
return my findContextNamed(rest of theContexts, contextName)
end using terms from
end findContextNamed
|
Almost. I still didn't quite get what I expected -- something to do with name matching for sub-contexts. But rather than chase it down, I just switched to an ID matching scheme. So:
Code:
tell application "OmniFocus"
tell document 1
set first_match to first item of (complete context_search_string as context maximum matches 1)
set the_ID to id of first_match
set found_context to my findContextByID(every context, the_id)
make new inbox task with properties {name:"test", context:found_context}
end tell
end tell
on findContextByID(theContexts, the_id)
if (theContexts is {}) then return missing value
set firstContext to item 1 of theContexts
using terms from application "OmniFocus"
if (id of firstContext is the_id) then return firstContext
set subContext to my findContextByID(every context of firstContext, the_id)
if (subContext is not missing value) then return subContext
return my findContextByID(rest of theContexts, the_id)
end using terms from
end findContextByID
Still seems crazy to me since OF has already done the work of finding the matching context.
Omniites: How about adding a 5th element to the returned records from the
complete command that is just a reference to the matching context (or project)?