View Single Post
Quote:
Originally Posted by Aires View Post
Somewhat related to this topic/request would be to have the ability to view filtered tasks based on string searches inside notes...
I haven't succeeded in controlling filtering through Applescript, but here is a script which highlights all tasks whose notes contain a user entered string - expanding those notes, and collapsing all other notes:

Code:
-- Open and highlight only those notes containing a specified string

on run
	set strSearch to GetSearchString()
	if length of strSearch > 0 then
		
		tell application id "com.omnigroup.OmniPlan"
			set oWin to front window
			set oDoc to front document
			set oProject to project of oDoc
			
			tell oWin
				set selected tasks to {}
				set lstSeln to selected tasks
			end tell
			
			set note expanded of every task of oProject to false
			set lstTasks to my NoteMatchTasks(oProject, strSearch)
			repeat with oTask in lstTasks
				tell oTask
					-- set filtered to true -- FAILS ...
					set note expanded to true
				end tell
			end repeat
			set selected tasks of oWin to lstTasks
		end tell
	end if
end run

on NoteMatchTasks(oProject, strSearch)
	tell application id "com.omnigroup.OmniPlan"
		set lstTasks to tasks of oProject where note ≠ ""
		set lstMatch to {}
		repeat with oTask in lstTasks
			set strNote to note of oTask
			if (offset of strSearch in strNote) > 0 then set end of lstMatch to oTask
		end repeat
		return lstMatch
	end tell
end NoteMatchTasks


on GetSearchString()
	tell (display dialog "String to search for in notes: " default answer "")
		text returned
	end tell
end GetSearchString