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 Today's Posts

 
Select a context from the side bar Thread Tools Search this Thread Display Modes
I've been trying to select a "found" context without luck. In this example, I'm selecting tree 2, but I would like to select the found "Grocery" context. Can anybody give me a pointer?

Thanks,
Eric
Code:
tell application "OmniFocus"
	
	set oContextList to contexts of first document
	set oContext to my FindContext("Grocery", oContextList)
	set cname to name of container of oContext
	tell front document to tell first document window to tell sidebar to tell library to select tree 2 
	-- of oContext
	set ttt to name of tree 2 of library of sidebar of first document window of front document
end tell


-- get a pointer to any defined context with this name
on FindContext(strName, oContexts)
	tell application "OmniFocus"
		ignoring case
			repeat with oContext in oContexts
				-- set strContextName to name of oContext
				if (name of oContext) = strName then
					return oContext
				else
					set oSubContexts to contexts of oContext
					if (count of (oSubContexts)) > 0 then
						set ContextFound to my FindContext(strName, oSubContexts)
						-- Check whether a context has in fact been found
						try
							set SomeName to name of ContextFound
							return ContextFound
						end try
					end if
				end if
			end repeat
		end ignoring
	end tell
end FindContext
 
You can take an even easier approach since you know its a descendant tree:

Code:
tell application "OmniFocus"
	first descendant tree of sidebar of document window 1 of document 1 whose name is "Grocery"
end tell
-P
 
Cool! Thanks. How do I select that branch, though?
 
Oh, never mind. I got it:

Code:
tell application "OmniFocus"
	select (the first descendant tree of sidebar of document window 1 of document 1 whose name is "Gym")
end tell
 
you may find your script fails if the context's ancestors are folded, or if the smart filter excludes that context at the present time.

Take a look in my reveal script, elsewhere on this site, for examples.
 
that's actually what my base was for this.
 
 




Similar Threads
Thread Thread Starter Forum Replies Last Post
Up and down bar on the right side of OF window. raphael OmniFocus 1 for Mac 5 2012-03-02 01:45 AM
OF Respect for Project Side bar selections when switching to Context kingsinger Applying OmniFocus 3 2011-08-28 03:54 PM
How to draw forms containing text and images side-by-side? -tm- OmniGraffle General 0 2010-03-28 08:39 AM
New "No Context" bucket has side effects jasong OmniFocus 1 for Mac 4 2007-09-20 02:09 PM


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


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