View Single Post
Where I am struggling with this script is in two areas, first is in setting the context. In a subsequent dialog I prompt for the context. I have seen the complete context code but can't seem to figure out how to get it to work.

If I can figure that part out I was thinking the code for creating the task would be something like...

Code:
set theSelectedTask to value of item 1 of theSelectedItems
set newTask to make new task with properties {name:theTaskName, context:theContext}
set assigned container of newTask to theProject
move newTask to before task 1 of theProject
Which all compiles OK, not sure if it will work until I figure out how to set the context.

Here is the complete code such that it is
Code:
tell application "OmniFocus"
	tell front document
		tell (first document window whose index is 1)
			set theSelectedItems to selected trees of content
			if ((count of theSelectedItems) < 1) then
				display alert "You must first select a single task." message "Select a single task before running this script." as warning
				return
			end if
			if ((count of theSelectedItems) > 1) then
				display alert "You must select only one task." message "Select a single task before running this script." as warning
				return
			end if
			
			display dialog "Enter the new next action for this project" buttons {"Cancel", "Add"} default button 2 default answer "" with title "New Next Action"
			if button returned of result is "Add" then
				set theTaskName to text returned of result
				display dialog "Enter the context" buttons {"Cancel", "Add"} default button 2 default answer "" with title "New Context"
				if button returned of result is "Add" then
					set newContext to text returned of result
				end if
				
				set MyContextList to complete newContext as context maximum matches 1
				set MyContextID to id of first item of MyContextList
				set theContext to context id MyContextID
				
				
				set theSelectedTask to value of item 1 of theSelectedItems
				set theProject to the name of the containing project of theSelectedTask
				set newTask to make new task with properties {name:theTaskName, context:theContext}
				set assigned container of newTask to theProject
				move newTask to before task 1 of theProject
			end if
		end tell
	end tell
end tell
The error I am getting now is in the line
set MyContextList to complete newContext as context maximum matches 1

and the error is OmniFocus got an error: "email" doesn’t understand the complete message. "email" was the value of new Context.

As you can see any help would be appreciated.

Thanks,

George

Last edited by gcrump; 2009-01-29 at 03:00 AM..