View Single Post
OK, I tried both methods, still without success.

First, I renamed the projects to folders, and ran this script:

Code:
tell application "OmniFocus"
	tell front document
		set theContext to the context "Online" of context "Mac"
		set theProject to the project "AP, AR, Finance" of folder "Operations & Finance" of folder "Work"
		tell content of document window 1 -- (first document window whose index is 1)
			set theSelectedItems to value of every selected tree
			if ((count of theSelectedItems) < 1) then
				display alert "You must first select an item to complete." as warning
				return
			end if
			repeat with anItem in theSelectedItems
				set context of anItem to theContext
				set due date of anItem to current date
				set project of anItem to theProject
			end repeat
		end tell
	end tell
end tell
I got this error:

Quote:
OmniFocus got an error: Can’t set project of inbox task id "lAwmI4fc0Eg" of document id "pDdrIS3xC2J" to project id "p_Kz1sJF5_h" of document id "pDdrIS3xC2J".
The project name and folder names are spelled correctly.

I also tried this, attempting to adopt Ken's code:

Code:
tell application "OmniFocus"
	tell front document
		set theContext to the context "Online" of context "Mac"
		set ProjectString to "AP, AR, Finance"
		tell content of document window 1 -- (first document window whose index is 1)
			set theSelectedItems to value of every selected tree
			if ((count of theSelectedItems) < 1) then
				display alert "You must first select an item to complete." as warning
				return
			end if
			repeat with anItem in theSelectedItems
				set context of anItem to theContext
				set due date of anItem to current date
				set MyProjectArray to complete project string as project maximum matches 1
				if ((count of MyProjectArray) > 0) then
					set MyProjectID to id of first item of MyProjectArray
					set ThisProject to project id MyProjectID
				else
					set ThisProject to (make project with properties {name:ProjectString})
				end if
			end repeat
		end tell
	end tell
end tell
I get this error:

Quote:
OmniFocus got an error: Can’t get project string of content of document window 1 of document 1.
Feeling like an idiot... But at least OmniFocus *does* correctly apply the changes to context & date.