View Single Post
George tagged me into the ring to help on this one.

Here's what I came up with, complete with LaunchBar integration to avoid the extra song and dance of the dialog. It also selects the new task on completion to make it easy to add context and whatnot to it.

Code:
on handle_string(s)
	of_followup(s)
end handle_string

on run
	of_followup("")
end run


on of_followup(taskname)
	tell application "OmniFocus" to tell document 1
		tell content of document window 1 to get value of descendant trees whose selected is true
		set selectedItems to result
		-- put a repeat here once it's troubleshot
		set xItem to item 1 of result
		get class of item 1 of result
		if result is task then
			set theProject to containing project of xItem
			set theContext to context of xItem
			if taskname is "" then
				display dialog "New task name is...?" default answer "Copy of " & (name of xItem)
				set taskname to text returned of result
			end if
			make new task at beginning of tasks of theProject with properties {name:taskname} --, context:(context of xItem)}
			set newTask to result
			tell content of document window 1 to select {newTask}
		else
			beep
		end if
	end tell
end of_followup