View Single Post
Quote:
Originally Posted by gshenaut View Post
Yes, that's in the right direction, but I don't want to "complete" a project name, I want to find the id of a specific project from its name. The completion method is inherently ambiguous.
On the complete method ...

The complete method has to be "inherently ambiguous" simply because the data is inherently ambiguous. Nothing prevents 2 projects (or 10 projects for that matter) from having identical names, so there can, alas, be no simple mapping of a name string onto a unique id.

You just have to remove the maximum matches parameter, see how many matches you have got in your data, and handle the harvest iteratively in the way that makes sense for your application.

Code:
tell application "OmniFocus"
	tell front document
		set lstMatches to complete strPattern as project
		set lngMatches to length of lstMatches
		if (lngMatches) > 1 then
			-- deal with the multiple matches ...
			repeat with recMatch in lstMatches
				set {_, lngScore, strID, strName} to recMatch as list
				
				-- handle each match here ...
				
			end repeat
		else if lngMatches > 0 then
			-- good ! you have a unique match !
		else
			-- sorry ! no matches at all !
		end if
	end tell
end tell