View Single Post
Some of this was cribbed from Curt Clifton's Populate Template Placeholders scripts. The basic idea is: let's say that you have a task selected in a 'Next Actions' list, or in Context mode, or whatever -- you can't see the entire project, and you would like to. This script will open a new window with focus set to the projects of whichever tasks (or projects) you currently have selected. Nothing more, but nothing less.

Hope it's useful
Jeremy

Code:
tell application "OmniFocus"
	tell front document
		tell document window 1 -- (first document window whose index is 1)
			set theSelectedItems to selected trees of content
			if ((count of theSelectedItems) < 1) then
				-- try sidebar selection
				set theSelectedItems to selected trees of sidebar
			end if
		end tell
		if ((count of theSelectedItems) < 1) then
			display alert "You must first select a project or a task." message "Select a project or task to focus on." as warning
			return
		end if
		set theSelection to {}
		repeat with i from 1 to count of theSelectedItems
			set selectedItem to the value of item i of theSelectedItems
			if class of selectedItem is task then
				set selectedItem to containing project of selectedItem
			end if
			copy selectedItem to end of theSelection
		end repeat
		
		set newWin to make new document window with properties {selected view mode identifier:"project", focus:theSelection}
	end tell
end tell