The Omni Group
These forums are now read-only. Please visit our new forums to participate in discussion. A new account will be required to post in the new forums. For more info on the switch, see this post. Thank you!

Go Back   The Omni Group Forums > OmniFocus > OmniFocus Extras
FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
Read tasks of "search term" result? Thread Tools Search this Thread Display Modes
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
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
 
Quote:
Originally Posted by digitalimago View Post
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
 
Hi Rob,

Thank you very much!
Works very fine.

Deborah
 
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Outliner Pro - Read the "hoursPerday" setting Simon Knight AppleScripting Omni Apps 5 2010-05-05 02:46 AM
Why "search iPhone" doesn't search in the OmniFocus database? avernet OmniFocus for iPhone 2 2010-01-20 10:52 AM
"Unable to Read Document" kevindaly iDisk/MobileMe/.Mac Syncing 3 2009-09-15 09:29 AM
"unable to read document" error fogboy OmniFocus 1 for Mac 2 2007-05-21 10:13 AM
"Mark all items read" -- why has this never worked? Stormchild OmniWeb General 5 2006-08-22 09:21 PM


All times are GMT -8. The time now is 08:57 AM.


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