View Single Post
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