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

 
How to select? Thread Tools Search this Thread Display Modes
How do you get the select command to work? I was writing a script to list all projects/SALs/groups without a default context, and got to the last step of letting the user go to a particular item, and can't get it to work: OmniFocus says project id blah of document id blah doesn’t understand the select message. I wrote some sample code for testing the select command in many combinations:

Code:
tell application "OmniFocus"
	set firstProject to project 1 of document 1
	--		result: project id "pbV93_WpDMx" of document id "mHxuR5tEH1i"
	set fpID to id of firstProject
	--		result: "pbV93_WpDMx"
	set fpClass to class of firstProject
	--		result: project
	display dialog fpID
	
	select firstProject
	--Error: project id "pbV93_WpDMx" of document id "mHxuR5tEH1i" doesn’t understand the select message.
	--All of the following produce a similar error:
	select {firstProject}
	tell document window 1 to select {firstProject}
	tell content of document window 1 to select {firstProject}
	tell front document
		activate
		select {project id fpID}
		select firstProject
		select (firstProject)
		select every item of {firstProject}
		tell content of window 1 to select firstProject
		tell content of window 1 to select {firstProject}
		tell content of window 1 to select every item of {firstProject}
	end tell
end tell
Any ideas?
Thanks,
David
 
OmniGraphSketcher release has kept me pretty busy, but David emailed us this week; I figured I'd post the useful bits of my reply here so other folks can find this in the future...

Quote:
Happy to help, and thanks for sending this in. Showed your email to the lead developer, who sent this back:
AS is funny. If you do "foo bar" then you are sending the command "foo"
to "bar" and in this case "project" doesn't handle "select".
See "close SomeWindow"; the window gets the command.
Wrapping foo in a list makes it not be considered and the receive of
the "tell" block gets it instead.

He sent along this script as an example:
tell application "OmniFocus 1.7"
tell default document
set MyProject1 to first project
tell front document window
tell sidebar -- or "tell content"
select {MyProject1}
end tell
end tell
end tell
end tell
 
Thanks for the help, that solved it. Select certainly is picky. I rewrote the sample with some additional explanation, and added selecting an action. If you only want to select a project or folder, leave out the 'tell content' block.

NOTE: code assumes there is a task in a project that is directly in the Library (not in a folder).
Code:
tell application "OmniFocus"
	tell default document
		-- example: get a reference to an action (task in Applescript) and its parent project
		set project1 to first project whose status is active
		set task1 to task 1 of project1 whose completed is false
		
		tell front document window
			-- The parent project of an action (task) must be selected before you can select the action.
			tell sidebar -- to select a project or folder, you must tell the sidebar
				select {project1} --must be a list
			end tell
			tell content -- to select an action, you must tell the content
				select {task1} --must be a list
				--The focus may be on the sidebar or the content, select doesn't change it.
				--The following should change focus to the content area:
				set selected to true -- bug in OmniFocus: doesn't work
			end tell
		end tell
	end tell
end tell
The bug that you can't get or set the selected property of the content or sidebar of a window is also shown.

I wrote OFSelectAny() to make it easier to select:
http://forums.omnigroup.com/showthread.php?t=11886

Last edited by davidamis; 2009-04-08 at 06:16 PM.. Reason: added link to OFSelectAny() post
 
 




Similar Threads
Thread Thread Starter Forum Replies Last Post
Select behind artdog OmniGraffle General 3 2010-09-09 02:50 AM
Select from one item to another? Roger Barre OmniOutliner 3 for Mac 0 2008-09-07 09:38 AM
How to select all level n vanity OmniOutliner 3 for Mac 6 2008-01-25 12:31 PM
How to *just* select a Project? santra OmniFocus 1 for Mac 12 2007-10-05 04:26 AM
non-linear select bjordan OmniOutliner 3 for Mac 1 2007-08-09 11:23 AM


All times are GMT -8. The time now is 10:27 AM.


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