For reference, here is the LaunchBar script which I use for focusing on Projects whose names contain a string entered at the Launchbar prompt.
Its a quick and simple approach, which just refocuses the current window on any projects (up to a maximum number) whose names contain the entered string.
Useful to me as I often have a small group of projects with related names.
Code:
(*
Run from Launchbar to refocus current window on any projects
whose names match a sub-string entered in Launchbar.
If the script is indexed in and summoned from Launchbar,
tapping spacebar will allow you enter enough of any substring
of a project name to uniquely identify it.
If the string entered turns out not to be unique,
then a list of candidate projects will get the focus in the current window.
(Useful to me as I often have a small set of projects with related names)
*)
property pstrTitle : "Focus on project"
property pmaxProjCount : 10
on handle_string(strprojectName)
if length of strprojectName > 0 then
tell application id "com.omnigroup.OmniFocus"
set oDoc to default document
set lstprojects to my ProjectsByName(oDoc, strprojectName)
if lstprojects is not missing value then
set focus of front document window of oDoc to lstprojects
else
display dialog "No projects with name containing " & return & return & ¬
tab & quote & strprojectName & quote & return & return & ¬
"found in the OF database" with title pstrTitle
end if
activate oDoc
end tell
end if
end handle_string
on ProjectsByName(oDoc, strName)
using terms from application "OmniFocus"
tell oDoc
set lstMatches to (complete strName as project ¬
maximum matches pmaxProjCount)
if length of lstMatches > 0 then
set lstprojects to {}
repeat with recMatch in lstMatches
set end of lstprojects to project id (id of recMatch)
end repeat
return lstprojects
else
return missing value
end if
end tell
end using terms from
end ProjectsByName