The Omni Group Forums

The Omni Group Forums (
-   OmniFocus Extras (
-   -   AppleScript help: Create sub-task, project from task (

iNik 2007-12-04 09:55 AM

AppleScript help: Create sub-task, project from task
I'm fairly certain I'm missing something obvious here, but how do I create or duplicate a task so that it's within (as a subtask of) another task?

Also, is there an easy way, via AppleScript, to turn a task into a project (as though it were dragged from the task view to the projects sidebar)?

Thanks for the help!

iNik 2007-12-04 11:22 AM

Hrm... It appears that the only way to create a sub-task is to tell the parent task to create a new task. Not exactly intuitive, but it works. (I'd expect make new task at <parent task> to be the syntax.)

Then there's create a project from a task. I seem to have to do that by grabbing the properties of the task. No big deal, really. But what I'm trying to do is have a one-click way to take a task and turn it into a project with that same task within the project. (Specifically to take a singleton in a bucket and turn it into its own project as soon as it becomes clear it'll take more steps -- i.e. if it gains a "waiting" action)

What I can't seem to do is assign a task to a project, which seems entirely nutty.

Tim Wood 2007-12-04 09:40 PM

Creating a project from a task would ideally work by just creating a new project "with properties {root task:MyTask}", but this isn't specifically implemented -- it might work, but there would be a root task that would probably get orphaned and then resurrected into the Inbox ... not good. I've logged <bug://bugs/43714> ('make new project' should accept a 'root task' in its properties) on this.

Assigning a task to an inbox item would just involve setting the 'assigned container' (can either use a project, its root task or any other task). With an existing task, you should just 'move' it where you want it (TN2106 says container properties should generally be read-only and 'move' should be used to update them).

Here are some examples:

tell application "OmniFocus"
tell default document
set MyProject1 to make new project with properties {name:"Test project 1"}
tell MyProject1
set MyAction to make new task with properties {name:"action"}
end tell

set MyProject2 to make new project with properties {name:"Test project 2"}
move MyAction to end of tasks of MyProject2

set MyProject3 to make new project with properties {name:"Test project 3"}
duplicate MyAction to end of tasks of MyProject3 with properties {note:"I'm in 3 now!"}

set MyInboxItem to make new inbox task with properties {name:"Stuffs"}
set assigned container of MyInboxItem to MyProject1
end tell
end tell

iNik 2007-12-05 09:53 AM

Thanks, Tim! That's a great help. I was missing the "move to end of tasks" portion and was just moving to the project itself (which threw an error).

All times are GMT -8. The time now is 03:08 AM.

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