You might find it useful to look at the sample "Send to OmniFocus" script which is bundled inside the app itself (in OmniFocus.app/Contents/Resources/SampleScripts/Send to OmniFocus.applescript).
In particular, it shows how you can use the
complete command to find a project or context using the same mechanism as Quick Entry's completion matching, like so:
Code:
set ProjectString to "AP, AR, Finance"
set ContextString to "Online"
set MyProjectArray to complete ProjectString as project maximum matches 1
try
set MyProjectID to id of first item of MyProjectArray
set ThisProject to project id MyProjectID
on error
set ThisProject to (make project with properties {name:ProjectString})
end try
set MyContextArray to complete ContextString as context maximum matches 1
if ((count of MyContextArray) > 0) then
set MyContextID to id of first item of MyContextArray
set ThisContext to context id MyContextID
else
set ThisContext to (make context with properties {name:ContextString})
end if
Note: I just copied the above code directly from the "Send to OmniFocus" script (other than the initial assignment), without editing. Looking at it now, I'm not sure why the project code uses try / on error to notice when a project is missing, while the context code simply checks the number of returned items. It seems to me that either way should work fine, but the second method seems more straightforward and perhaps a little more efficient.