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) |
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] |
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] |
That is indeed a much better idea. Thanks.
|
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] |
[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. |
Very few arrive like Athena, springing forth fully armed from the head of Zeus :-)
|
Many are called but few are chosen.
|
All times are GMT -8. The time now is 01:01 PM. |
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.