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