PDA

View Full Version : Fetching all OmniPlan tasks


psidnell
2012-02-05, 07:32 AM
I'm trying to extract all the tasks from an OmniPlan document and I'm adapting one of Rob Trew's scripts to send OP tasks to OF so that it creates a TaskPaper document instead. It's working, but currently the script is only sending the selected tasks:


tell window 1
set lstOPTasks to selected tasks of it
end tell


And I want to send the whole document without having to select, using something like:


tell document 1 of it
set lstOPTasks to task of it
end tell


Unfortunately the second form seems seems to have done a recursive descent of all tasks to populate the list, while leaving the descendants of each task intact. Consequently I see every task twice.

It there a way to get hold of some phantom root task or just the top level tasks?

Thanks

(have pity: I only opened "Learn AppleScript" on Friday)

psidnell
2012-02-05, 07:42 AM
Answered my own question just filtered the list:

tell document 1 of it
set allTasks to task of it
set lstOPTasks to {}
repeat with aTask in allTasks
if (outline depth of aTask) is 1 then
set end of lstOPTasks to aTask
end if
end repeat
end tell

whpalmer4
2012-02-05, 07:45 AM
If you're munging the script I think you are, replacing OPSelected() with the following code should change its behavior to send all tasks if none are selected, otherwise only the selected ones:


on OPSelected()
tell application "OmniPlan"
tell front window
if (count of selected tasks) > 0 then
set lstOPTasks to selected tasks
else
set lstOPTasks to (every child task)
end if
if (count of lstOPTasks) > 0 then
return my Tasks2NameList(lstOPTasks)
else
return {}
end if
end tell
end tell
end OPSelected

psidnell
2012-02-05, 07:48 AM
That is indeed a much better idea. Thanks.

whpalmer4
2012-02-05, 07:50 AM
A more idiomatic (and efficient) way of doing your filtering might be:


tell document 1 of it
set lstOPTasks to (every task whose outline depth is 1)
end tell

psidnell
2012-02-05, 07:56 AM
A more idiomatic (and efficient) way of doing your filtering might be:

You should see the rest of my script, you would probably weep.

whpalmer4
2012-02-05, 08:07 AM
Very few arrive like Athena, springing forth fully armed from the head of Zeus :-)

psidnell
2012-02-05, 08:18 AM
Many are called but few are chosen.