The Omni Group Forums

The Omni Group Forums (http://forums.omnigroup.com/index.php)
-   AppleScripting Omni Apps (http://forums.omnigroup.com/forumdisplay.php?f=46)
-   -   Fetching all OmniPlan tasks (http://forums.omnigroup.com/showthread.php?t=23409)

psidnell 2012-02-05 07:32 AM

Fetching all OmniPlan tasks
 
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:

[CODE]
tell window 1
set lstOPTasks to selected tasks of it
end tell
[/CODE]

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

[CODE]
tell document 1 of it
set lstOPTasks to task of it
end tell
[/CODE]

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

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:

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

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:

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

psidnell 2012-02-05 07:56 AM

[QUOTE=whpalmer4;107036]A more idiomatic (and efficient) way of doing your filtering might be:[/QUOTE]

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.


All times are GMT -8. The time now is 05:47 AM.

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