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

 
What's my parent? Thread Tools Search this Thread Display Modes
At some point my script needs to know whether the task it is dealing with is contained directly by its project, or in a task group.
I figured it out but it doesn't look very convincing. Is there a better way?
Here's my code:
Code:
if id of container of thisTask ≠ id of containing project of thisTask then
		-- it's in a task group
		-- do the appropiate thing
	else
		--do the other thing
	end if

Last edited by teobaldo; 2011-02-21 at 11:29 AM..
 
I might use some variant of

parent task is root task of containing project

Code:
tell application id "com.omnigroup.omnifocus"
	tell content of front document window of front document
		set lstTasks to value of selected trees
		set oTask to first item of lstTasks
		tell oTask
			set blnIsInGroup to (parent task is not root task of containing project)
		end tell
	end tell
end tell
 
or, of course:

Code:
set blnInGroup to (container is not root task of containing project)
but I notice that the execution speed of your approach:

Code:
set blnInGroup to (id of container ≠ id of containing project)
is fractionally faster ...

--

Last edited by RobTrew; 2011-02-20 at 11:06 AM..
 
Oh, great.
I picked the 'best' solution... :grin:
Not that it is that great.
Would be easier with a 'task group' class.
 
I needed this in order to work around the absence of a 'task group' class.
When importing, projects are created in expanded state, but task groups are not. They can't be, because they only become task groups after a child is created (obvious when you have experienced the mess which results when ignoring this).

The script now checks in what type of container a list of tasks will be created.
If it's a task, the script expands the new task group after the first child is created.
Now it can also paste the childrens' notes, which is the purpose of the exercise.
(I use UI scripting because my notes have a lot of formatting, which I do not want to loose).

Earlier I was trying to do this in the routine which creates the tasks, but after some reshuffling the solution became somewhat simpler.
Here is the routine that processes the task list:
Code:
-- Recursively create tasks in current project
-- Flag condition where parent is a task
-- parameters:	list of tasks in Mori
--		OmniFocus item in which to create tasks from entryList
--		(a project on first entry)
-- returns:	nothing
on processEntries(entryList, refOmniNode)
	tell front document of application "Mori"
		set currentNode to ""
		tell front document of application "OmniFocus" to set boolIsTask to (class of refOmniNode is task)
		set taskCount to count entryList
		repeat with i from 1 to taskCount
			set refMoriTask to item i of entryList
			-- tell subroutine to only expand parent first time
			set boolExpandParent to (i = 1 and boolIsTask)
			set currentNode to my createTask(refMoriTask, refOmniNode, boolExpandParent)
			if entries of refMoriTask is not {} then -- has children
				set children to my listEntriesSorted(refMoriTask)
				my processEntries(children, currentNode) -- go deeper
			end if
		end repeat
	end tell
end processEntries

Last edited by teobaldo; 2011-02-21 at 11:37 AM..
 
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Keep Child from inheriting from Parent joeworkman OmniOutliner 3 for Mac 0 2011-08-03 05:03 PM
Parent group totals Cmalumphy OmniOutliner for iPad 3 2011-05-15 07:03 PM
child tab after parent, not end of all? dru OmniWeb General 6 2011-04-21 01:44 PM
Parent/child question peterlemer OmniFocus 1 for Mac 3 2008-10-11 09:20 AM
Parent-only handle option Nick Sloan OmniOutliner 3 for Mac 0 2007-11-13 10:28 PM


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


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