Set project when creating task in quick entry (Applescript)


#1

This works for creating a task with an assigned project:

tell application "OmniFocus"
tell default document
	set theProject to first flattened project where its name = "Project Name"
	make new inbox task with properties {name:"Task Name", note:"Task Note", assigned container:theProject}
end tell
end tell

But this fails:

tell application "OmniFocus"
	tell default document
		set theProject to first flattened project where its name = "Project Name"
		tell quick entry
			make new inbox task with properties {name:"Task Name", note:"Task Note", assigned container:theProject}
			open
		end tell
	end tell
end tell

The error is “Attempted to mix self with an object from another document.”. The “set theProject” line doesn’t work if it’s inside the “tell quick entry” block.

Not sure where to go from here, any ideas?


#2

Not using AppleScript these days but remember that the Quick Entry Tree class contains projects, similar to the Document class. They refer to the same projects, but are in fact different objects. I think you need to address the project that is contained in the Quick Entry object.

c8d92fb7495f8b40852e8863689ae458f5204c07%20copy

Unfortunately, it doesn’t have a .flattenedProjects property, so you will need to recurse in order to address it (in case your OmniFocus Database structure isn’t a flat list of projects).