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

 
How do I move a project to a specific folder? Thread Tools Search this Thread Display Modes
I am trying to figure out how to move a project from the bottom of the projects list to a specified folder. I am starting by figuring out how to duplicate a selected project to another location. I have:

Code:
tell application "OmniFocus"
	tell front document
		tell document window 1
			set theSelectedItems to selected trees of sidebar
			set theA to {tree 2 of tree 2 of sidebar of document window id 128 of document id "fqCMFexKSD8" of application "OmniFocus"}
			set theX to (value of item 1 of theSelectedItems)
			set theY to folder of theX
			set theZ to section of theY
			duplicate (value of item 1 of theSelectedItems) to after theA
		end tell
	end tell
end tell
I get:
  • "OmniFocus got an error: Can’t make {tree 2 of tree 2 of sidebar of document window id 128 of document id "fqCMFexKSD8"} into type specifier," when when I try to duplicate the project to after theA.
  • "OmniFocus got an error: Attempted to move data objects to a nil container," when I try to duplicate the project to after theX and theY.
  • "OmniFocus got an error: Can’t make {project id "oxQPHIP8MtA" of document id "fqCMFexKSD8", etc.} into type specifier," when I try to duplicate the project to after theZ.

How do I write a command that will move the selected project to a specified location?

Thanks,
Rebecca
 
On a related note, why is it that:
set theX to (first section whose name is "Vision")
duplicate newTemplate to after theX
does not work, but
duplicate newTemplate to after (first section whose name is "Vision")
does? Grrr.
 
Quote:
Originally Posted by rloconne View Post
On a related note, why is it that:
set theX to (first section whose name is "Vision")
duplicate newTemplate to after theX
does not work

Try:
set theX to a reference to (first section whose name is "Vision")
duplicate newTemplate to after theX
 
I get the error: "OmniFocus got an error: Attempted to move data objects to a nil container." (I am getting really sick of that *#$$ nil container.)

The best solution I have found so far is to move the project from its original position at the bottom of the list to the top level section containing the folder I want the project in, then to the second level section within that section, and so on until I get it to where I want to go:

Code:
-- treePath is a path like "{FolderTop: Folder level 2: etc}"; getPathParts turns it into a list: {"FolderTop", "Folder level 2", "etc"}; newTemplate is a project reference
on moveToSection(treePath, newTemplate)
	tell application "OmniFocus"
		tell front document
			set treePathParts to my getPathParts(treePath)
			
			try
				move newTemplate to after (first section whose name is (item 1 of treePathParts))
				set currentSection to (first section whose name is (item 1 of treePathParts))
			on error
				return false
			end try
			repeat with i from 2 to count of treePathParts
				try
					move newTemplate to after (first section of currentSection whose name is (item i of treePathParts))
					set currentSection to (first section of currentSection whose name is (item i of treePathParts))
				on error errMsg
					return false
					-- The one of the folders named does not exist
				end try
			end repeat
			move newTemplate to after (last section of currentSection)
		end tell
		return currentSection
	end tell
end moveToSection
It works, but it is really slow.

Last edited by rloconne; 2008-01-21 at 08:34 PM..
 
Re: moveToSection

When I say it works, I mean it works as long as the folder you want to move your project to is visible. I'm going to settle for that, but if anyone comes up with a better way to move a project to a folder specified by a string in a note, by all means, please let me know.
 
I have finished version 1 of the scripts I refer to in this thread. You can get them at http://people.engr.ncsu.edu/rloconne...g-projects.htm
 
Okay, so I didn't settle.

The magic code is:
Code:
tell application "OmniFocus"
	tell front document
		tell document window 1 -- (first document window whose index is 1)
			set theSelectedItems to selected trees of sidebar
			set theProject to value of item 1 of theSelectedItems
		end tell
move theProject to before [or after] the (first [or last] section of (first folder whose name is "Bottom Level Folder") of (first folder whose name is "Second Level Folder") of (first folder whose name is "Top Level Folder"))
As for why this was difficult to figure out:

There are two frequently used ways to interact with OmniFocus:
Code:
tell application "OmniFocus"
	tell front document
end tell
end tell
Code:
tell application "OmniFocus"
	tell front document
		tell document window 1
end tell
end tell
end tell
You interact with just the "front document" primarily when you want to work with section, projects, folders, and tasks. You interact with a "document window" of the front document (or some other document) when you want to interact with a tree. Trees are primarily useful for interacting with the current view of your document and the current selection.

Problems occur when you try to interact with sections, projects, folders and tasks inside a "tell document window [number, usually 1]" declaration. It tells you it can't get things, and other odd error messages.

On the other hand, you need to use this declaration to interact with trees, including the "sidebar tree" the "content tree" and the "library tree". If you try to interact with these trees outside of the "tell document window [number]" declaration, you will get errors starting with the words "Can't get...".

You move from trees to projects by setting a variable to the "value of" a tree, and then doing whatever you need to do to it outside of the "tell document window [number]" declaration.

And then you live happily ever after (for now).
 
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
can't move pre-existing project in to pre-existing folder kbs1138 OmniFocus 1 for Mac 3 2011-06-16 11:22 AM
script to make an inactive project active and move it to a selected folder kingsinger OmniFocus Extras 2 2010-11-15 09:52 PM
How to move project into folder? [A: Tap Edit, tap item, tap "move" button in Tbar.] Avis OmniFocus for iPhone 4 2010-07-07 11:27 AM
Feature Request: Move project from folder to folder jbarr OmniFocus for iPhone 2 2008-07-17 12:10 PM
Please move datafile to Documents folder jasong OmniFocus 1 for Mac 18 2007-11-20 10:51 AM


All times are GMT -8. The time now is 09:17 PM.


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