View Single Post
I think you should be able to deflag everything that is shown in a particular perspective with something like this.

Code:
tell application id "OFOC"
	tell front document window of front document
		set refTrees to a reference to trees of content
		
		-- UN-FLAG ANY VISIBLE PROJECTS
		repeat with oProj in (value of refTrees where class of its value is project) as list
			set flagged of oProj to false
		end repeat
		
		-- TOP LEVEL TASKS
		repeat with oValue in (value of refTrees where class of its value is task) as list
			my ClearFlag(oValue)
		end repeat
		
		--  AND CHILD TASKS 
		-- if we are grouping by flag, the Flagged tree may vanish at run time
		repeat with i from (count of refTrees) to 1 by -1
			set oTree to item i of refTrees
			repeat with oTask in (value of descendant trees of oTree) as list
				my ClearFlag(oTask)
			end repeat
		end repeat
		
		-- WORKING AROUND AN OMNIFOCUS GUI BUG ...
		-- Note a bug in the GUI: project flags will not appear as cleared until the window is closed & reopened
		--  the following simply the view mode back and forth to force a repaint
		-- a time-waster, but works around the GUI bug
		set lstView to available view mode identifiers
		if item 1 of lstView = selected view mode identifier then set lstView to reverse of lstView
		repeat with oView in lstView
			set selected view mode identifier to oView
		end repeat
	end tell
end tell

on ClearFlag(oTask)
	tell application id "OFOC"
		set flagged of oTask to false
		set oParent to container of oTask
		repeat while class of oParent is in {task, project}
			set flagged of oParent to false
			set oParent to container of oParent
		end repeat
	end tell
end ClearFlag
Note that OmniFocus still seems to have a screen refresh bug - when the flagging of a Project is cleared by script, the flag icon is not immediately repainted/cleared - you have to close and reopen the window to see what has really happened.
Flags on cleared tasks, however, should immediately vanish.

I remember this bug from years ago, so I am a bit surprised to notice that it is still there. Certainly worth a bug report through OF > Help > Send Feedback ...

--

Last edited by RobTrew; 2012-01-25 at 09:51 PM.. Reason: Amended code to clear project flags in Context view