The Omni Group Forums

The Omni Group Forums (http://forums.omnigroup.com/index.php)
-   OmniFocus Extras (http://forums.omnigroup.com/forumdisplay.php?f=44)
-   -   Read tasks of "search term" result? (http://forums.omnigroup.com/showthread.php?t=15766)

digitalimago 2010-03-24 02:16 PM

Read tasks of "search term" result?
 
I'm trying to search for a particular string in a task name and then edit this task.

I can search for the task containing "xyz" with this code:

[CODE]
set searchstring to "xyz"
tell application "OmniFocus"
tell front document
tell document window 1
set search term to searchstring

end tell
end tell
end tell
[/CODE]

But then I do not know how to access the task that was found in the tree.
How can I solve this. Does anyone have a hint how to access the task?

Thanks
Deborah

RobTrew 2010-03-24 08:19 PM

[QUOTE=digitalimago;75022]I'm trying to search for a particular string in a task name and then edit this task[/QUOTE]


Here is an illustrative function [B]ObjectsFound([I]SearchString[/I])[/B], 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
[/CODE]

digitalimago 2010-03-24 10:49 PM

Hi Rob,

Thank you very much!
Works very fine.

Deborah


All times are GMT -8. The time now is 02:57 PM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.