How to assign an existing project to a task in Applescript?

I can assign a project to a task in the inbox

tell application "OmniFocus"
set oproject to (first flattened project of default document whose name is "MyProject")
tell content of first document window of front document
	set theSel to value of (selected trees where class of its value is not item and class of its value is not folder)
	
	
	repeat with theTask in theSel
		set assigned container of theTask to oproject
	end repeat
	end tell
end tell

But how do I assign an existing project to a task which is not in the inbox?

Perhaps with this line ?

move theTask to end of tasks of oproject

That worked! 😃

tell application “OmniFocus”

set oproject to ( first flattened project of default document whose name is “MyProject”)

tell content of first document window of front document

set theSel to value of ( selected trees where class of its value is not item and class of its value is not folder )

repeat with theTask in theSel

try

set assigned container of theTask to oproject

end try

try

move theTask to end of tasks of oproject

end try

end repeat

end tell

end tell