PDA

View Full Version : Selecting new tasks via Applescript


scb
09-06-2007, 08:18 AM
Once I make a new task using applescript, I'd like it to be selected for further editing. I tried this and it didn't work:

tell theProject
set thetask to (make new task with properties {start date:todayDate, name:subj, note:messagebody, context:theContext})
select thetask
end tell

Anyone have an idea how to make this work? I'm open to GUI scripting solutions.

Tim Wood
09-06-2007, 08:31 AM
The document itself doesn't have any support for selection; this is in the interface (since there can be multiple windows open, for one thing).

So, you can make and select a project like:

tell app "OmniFocus" to tell default document
set MyProject to make new project with properties {name:"My Project"}
tell sidebar of front document window
select {MyProject}
end
end

This will require that you have appropriate view settings (project mode, active projects). Also, if your focus set doesn't contain the project's folder, then the selection will fail with an error. Also, if you create the project in a folder that isn't expanded (or itself has an collapsed containing folder), then the selection apparently fails without an error. There is at least one bug in here... =)

scb
09-06-2007, 06:42 PM
Thanks for the response. However, I'd like to select a task, not a project. I'd really appreciate it if you could tell me how to select a specific task, both in project mode and context mode, assuming the task has both a project and a context assigned.

Tim Wood
09-06-2007, 11:30 PM
Ah; it should work with tasks just fine too -- you can do "select {MyTask1}" to select the task, but since tasks only show up in the content tree, you'd do:

tell content of front document window
select {MyTask}
end

to select the task. This works the same in project & context mode -- you can switch which mode the window is in by setting the document window's view mode identifier (there is a 'available view mode identifiers' list, currently just "project" and "context" and a 'selected view mode identifier').