Guest
2010-03-24, 08:19 PM
Quote:
Originally Posted by digitalimago
I'm trying to search for a particular string in a task name and then edit this task
|
Here is an illustrative function
ObjectsFound(SearchString), and an example of its use.
Code:
property pSearchString : "xyz"
-- Returns leaves of content matched by search string
on ObjectsFound(strSearch)
tell application "OmniFocus"
tell default document
set lstWins to document windows
if (count of lstWins) > 0 then
set oWin to first item of lstWins
else
set oWin to make new window
end if
tell oWin
set search term to strSearch
return leaves of content
end tell
end tell
end tell
end ObjectsFound
-- EXAMPLE: using ObjectsFound() function to process matching leaves of the content tree
on run
using terms from application "OmniFocus"
set strList to ""
-- get the matching leaves of the content tree
set lstLeaves to my ObjectsFound(pSearchString)
-- loop through the leaves and do something with their values
repeat with oLeaf in lstLeaves
set oValue to value of oLeaf
tell oValue
set cClass to class
if cClass is project then
set strList to strList & "Project: " & name & return
else if cClass is task then
set strList to strList & "Task: " & name & return
else if cClass is inbox task then
set strList to strList & "Inbox Task: " & name & return
else -- other class
set strList to strList & "???: " & name & return
end if
end tell
end repeat
if length of strList > 0 then
display dialog strList
else
display dialog pSearchString & " not found"
end if
end using terms from
end run
Last edited by RobTrew; 2010-03-24 at 08:44 PM..
Reason: Brought illustrative function to the top