The Omni Group Forums

The Omni Group Forums (http://forums.omnigroup.com/index.php)
-   OmniFocus Extras (http://forums.omnigroup.com/forumdisplay.php?f=44)
-   -   How do I move a project to a specific folder? (http://forums.omnigroup.com/showthread.php?t=6814)

rloconne 2008-01-17 03:42 PM

How do I move a project to a specific folder?
 
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[/CODE]

I get:[LIST][*]"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 [I]theA[/I].[*]"OmniFocus got an error: Attempted to move data objects to a nil container," when I try to duplicate the project to after [I]theX[/I] and [I]theY[/I].[*]"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 [I]theZ[/I].[/LIST]
How do I write a command that will move the selected project to a specified location?

Thanks,
Rebecca

rloconne 2008-01-18 05:15 PM

On a related note, why is it that:[INDENT]set theX to (first section whose name is "Vision")
duplicate newTemplate to after theX[/INDENT]does not work, but[INDENT]duplicate newTemplate to after (first section whose name is "Vision")
[/INDENT]does? Grrr.

RobTrew 2008-01-20 03:34 AM

[QUOTE=rloconne;31508]On a related note, why is it that:[INDENT]set theX to (first section whose name is "Vision")
duplicate newTemplate to after theX[/INDENT]does not work[/QUOTE]


Try:[INDENT]set theX to [B]a reference to[/B] (first section whose name is "Vision")
duplicate newTemplate to after theX[/INDENT]

rloconne 2008-01-21 07:31 PM

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
[/CODE]

It works, but it is really slow.

rloconne 2008-01-22 03:14 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.

rloconne 2008-01-22 05:34 PM

I have finished version 1 of the scripts I refer to in this thread. You can get them at [url]http://people.engr.ncsu.edu/rloconne/coding-projects.htm[/url]

rloconne 2008-01-24 04:13 PM

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"))[/CODE]

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]
[CODE]
tell application "OmniFocus"
tell front document
tell document window 1
end tell
end tell
end tell[/CODE]
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 [I]outside[/I] of the "tell document window [number]" declaration.

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


All times are GMT -8. The time now is 02:10 PM.

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