The Omni Group
These forums are now read-only. Please visit our new forums to participate in discussion. A new account will be required to post in the new forums. For more info on the switch, see this post. Thank you!

Go Back   The Omni Group Forums > OmniFocus > OmniFocus Extras
FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
Return all tasks that are nested under a folder? Thread Tools Search this Thread Display Modes
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
 
Thanks Rob

I'm getting an error when changing the line

Code:
set oFolder to first folder
to

Code:
set oFolder to "myFolder"
Quote:
error "Can’t get every flattened project of \"myFolder\"." number -1728 from every «class FCfx» of "myFolder"
 
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
 
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 missing value as their context, and a missing value 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.
 
Why does

Code:
(flattened projects of oFolder)
give me a list of projects in a folder where

Code:
(flattened projects where folder is not missing value and folder is oFolder)
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?
 
Reference ambiguities can often by resolved (to the innermost scope) by using the keyword its

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
 
Thanks. I am really beginning to dislike applescript...
 
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
nested tasks in forecast mavric OmniFocus 1 for Mac 2 2013-01-29 03:34 PM
When to use nested tasks? Derekasaurus Applying OmniFocus 2 2011-03-14 07:26 AM
EMail folder dedicated for tasks JackTB Applying OmniFocus 0 2010-06-25 10:33 AM
Nested tasks don't inherit due dates enricofra OmniFocus 1 for Mac 4 2008-03-26 09:39 AM
hitting return with a folder selected... seebs OmniFocus 1 for Mac 4 2007-09-25 07:11 AM


All times are GMT -8. The time now is 11:03 PM.


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