Quote:
Originally Posted by gcrump
How Can I get it to only search folder names instead of Project Names?
|
George's idea seemed useful, but adding it to the existing Focus On script was too slow. So, I created a new script "Focus on Folder" that works essentially like the existing one described above, but only searches folder names.
One other difference: the text entered for the search must be appear as contiguous characters in the folder name. That is, a search for “UFO” would match “Documented UFO sightings” but would not match “Founded Ungulates For Obama”. Without a built-in
complete command for folder names anything but exact substring matching is too slow.
Here's the new script. Install it and use it like the other one, but call it something different so you can use both scripts.
Code:
(*
This script lets you use LaunchBar to open a new OmniFocus window focused on
a folder that matches a given string.
by Curt Clifton, portions derived from code due to gcrump (George) on the
OF Extras forum.
http://forums.omnigroup.com/showpost.php?p=37275&postcount=13
*)
on run {}
my handle_string("374")
end run
on handle_string(FolderString)
if FolderString is not "" then
tell application "OmniFocus"
set mainDoc to default document
set omniFocusFolders to my getFolders(FolderString, mainDoc)
tell mainDoc
if (count of omniFocusFolders) is 0 then
beep
return
else if (count of omniFocusFolders) > 1 then
set choices to reverse of my getNames(omniFocusFolders, {})
set choice to choose from list choices without empty selection allowed
set folderID to my getIDByName(omniFocusFolders, item 1 of choice)
else
set folderID to id of first item of omniFocusFolders
end if
set folderObject to folder id folderID
set newW to make document window with properties {focus:{folderObject}, selected view mode identifier:"project", search term:""}
set (selected smart group identifier of sidebar of newW) to "remaining-projects"
set selected task state filter identifier of content of newW to "incomplete"
-- set selected task state filter identifier of content of newW to "all"
activate
end tell
end tell
open location "omnifocus:"
end if
end handle_string
on getFolders(FolderString, omniFocusDocument)
using terms from application "OmniFocus"
tell omniFocusDocument
set theSections to every section whose class is folder
return my accumulateMatches(FolderString, theSections, {})
end tell
end using terms from
end getFolders
on accumulateMatches(FolderString, theFolders, Accum)
if (theFolders is {}) then
return Accum
end if
return accumulateMatches(FolderString, rest of theFolders, accumulateMatchesHelper(FolderString, item 1 of theFolders, Accum))
end accumulateMatches
on accumulateMatchesHelper(FolderString, aFolder, Accum)
using terms from application "OmniFocus"
if (my matches(name of aFolder, FolderString)) then
set Accum to {aFolder} & Accum
end if
set theSubfolders to every section of aFolder whose class is folder
return accumulateMatches(FolderString, theSubfolders, Accum)
end using terms from
end accumulateMatchesHelper
on matches(folderName, matchString)
return folderName contains matchString
end matches
on getIDByName(XMLRecords, theName)
if XMLRecords is {} then
beep
error "No record selected"
end if
set oneName to (name of item 1 of XMLRecords)
log oneName
if oneName is theName then
return id of item 1 of XMLRecords
else
return getIDByName(rest of XMLRecords, theName)
end if
end getIDByName
on getNames(XMLRecords, Accum)
if XMLRecords is {} then
return Accum
else
return getNames(rest of XMLRecords, ({name of (item 1 of XMLRecords)} & Accum))
end if
end getNames