The Omni Group Forums

The Omni Group Forums (http://forums.omnigroup.com/index.php)
-   OmniFocus Extras (http://forums.omnigroup.com/forumdisplay.php?f=44)
-   -   Return all tasks that are nested under a folder? (http://forums.omnigroup.com/showthread.php?t=26011)

RobTrew 2012-10-03 11:41 AM

Return all tasks that are nested under a folder?
 
Just been asked this in a private message. Public discussion spreads the load and brings better harvests, so here's a first seedling.

[CODE]tell application id "OFOC"
tell default document
-- SOME FOLDER, LET'S JUST GRAB THE FIRST WE SEE ...
set oFolder to first folder

-- ALL ACTIVE CHILD-BEARING PROJECTS ENCLOSED BY THIS FOLDER, REGARDLESS OF NESTING
set refProjects to a reference to (flattened projects of oFolder where number of tasks > 0 and status is active)

-- HARVEST THE PROGENY THEREOF (PERHAPS FILTERED) AS A LIST OF LISTS
set lstTasks to flattened tasks of refProjects where completed is false

-- FLATTEN THE LIST, IF NEED BE
set lstTasks to my FlatList(lstTasks)
end tell
end tell


on FlatList(lst)
if class of lst is not list then
{lst}
else if lst ≠ {} then
FlatList(item 1 of lst) & (FlatList(rest of lst))
else
{}
end if
end FlatList[/CODE]

rhysbwaller 2012-10-03 04:30 PM

Thanks Rob

I'm getting an error when changing the line

[code]set oFolder to first folder[/code]

to

[code]set oFolder to "myFolder"[/code]

[QUOTE]error "Can’t get every flattened project of \"myFolder\"." number -1728 from every «class FCfx» of "myFolder"[/QUOTE]

rhysbwaller 2012-10-03 08:31 PM

Further to the error above, I'm getting an error when calling the task's context. See code snippet below


[CODE]tell application id "OFOC"
set dteNow to (current date)
tell default document
-- SOME FOLDER, LET'S JUST GRAB THE FIRST WE SEE ...
set oFolder to first folder

-- ALL ACTIVE CHILD-BEARING PROJECTS ENCLOSED BY THIS FOLDER, REGARDLESS OF NESTING
set refProjects to a reference to (flattened projects of oFolder where number of tasks > 0 and status is active)

-- HARVEST THE PROGENY THEREOF (PERHAPS FILTERED) AS A LIST OF LISTS
set lstTasks to flattened tasks of refProjects where completed is false

-- FLATTEN THE LIST, IF NEED BE
set lstTasks to my FlatList(lstTasks)

set listExport to "Task Project Context Creation Date Date Due Priority" & return

repeat with task_obj in lstTasks

set taskDueDate to ""
set taskPriority to ""
if due date of task_obj is not missing value then set taskDueDate to due date of task_obj
if flagged of task_obj is true then set taskPriority to "Yes"
set listExport to listExport & name of task_obj & " " & name of containing project of task_obj & " " & name of context of task_obj & " " & creation date of task_obj & " " & taskDueDate & " " & taskPriority & " " & return
end repeat

end tell

tell application "TextEdit"
activate
make new document
set text of document 1 to listExport as text
save document 1 in "/Users/myUser/Desktop/output.txt"
end tell

end tell


on FlatList(lst)
if class of lst is not list then
{lst}
else if lst ≠ {} then
FlatList(item 1 of lst) & (FlatList(rest of lst))
else
{}
end if
end FlatList[/CODE]

RobTrew 2012-10-03 11:14 PM

The first problem is that you are not assigning oFolder to a folder object, you are assigning it to a string. Strings don't have the properties of an OF folder.

You will find examples of how to get a reference to a folder object in various code examples in this forum.

The second problem is that some tasks will return [I]missing value[/I] as their context, and a [I]missing value[/I] does not have a name property.

Just before you get to that line, you will need to test the context of each task, assigning an empty string to a variable if the tasks's context is a missing value, and the context name otherwise.

enderw88 2013-06-25 01:20 PM

Why does

[CODE](flattened projects of oFolder)[/CODE]

give me a list of projects in a folder where

[CODE](flattened projects where folder is not missing value and folder is oFolder)[/CODE]

give me a type error?

Obviously it interpreting "folder" as a type rather than a field in the project object...but what syntax would make applescript interpret it as a field value rther than a type?

RobTrew 2013-06-25 03:01 PM

Reference ambiguities can often by resolved (to the innermost scope) by using the keyword [I]its[/I]

This works:

[CODE]tell application id "OFOC"
tell default document
set oFolder to first folder
set lstProj to (flattened projects where its folder is not missing value and its folder is oFolder)
end tell
end tell[/CODE]

enderw88 2013-06-25 05:36 PM

Thanks. I am really beginning to dislike applescript...


All times are GMT -8. The time now is 07:36 AM.

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