View Single Post
Quote:
Originally Posted by JLGray View Post
how do you deal with the possibility that within a reasonably complex hierarchy several rows matching the search query will be returned.
You get a union of the full list of ancestors - that is, purge any duplicate ancestors before printing the trees.

Code:
SubTreeMatch("bob")

on SubTreeMatch(strSearch)
	tell application id "OOut"
		tell front document
			set lstRows to rows where topic contains strSearch
			set lstAncestors to my GetAncestors(lstRows)
		end tell
	end tell
	
	-- Process unique list of ancestors
	-- ...
	
end SubTreeMatch


-- Purge any duplicate ancestors
on GetAncestors(lstRows)
	set lstUnion to {}
	tell application id "OOut"
		repeat with oRow in lstRows
			tell oRow
				if level > 1 then
					set strID to id of (last ancestor)
				else
					set strID to id of it
				end if
			end tell
			if not (lstUnion contains strID) then set end of lstUnion to strID
		end repeat
		if lstUnion ≠ {} then
			tell front document
				repeat with i from 1 to length of lstUnion
					set item i of lstUnion to row id (item i of lstUnion)
				end repeat
			end tell
			lstUnion
		else
			{}
		end if
	end tell
end GetAncestors
Quote:
Originally Posted by JLGray View Post
is there a way to tell what type of object you're dealing with in Apple Script?
Yes, objects have a class property.

Code:
if class of oObject is document then ...