View Single Post
Here's yet another variation! This one prompts for a context name substring to match, in response to another thread where this sort of is being discussed. The new state for each context is independently determined, though to make full use of that, you might want to change the logic to have it just go between two states (active/dropped or active/on hold being the likely candidates) instead of active/on hold/dropped as is done here. Left as an exercise for the reader :-)

Code:
tell application "OmniFocus"
	-- prompt user for context substring to match
	set Matchstr to text returned of (display dialog 
		"Context substring to match" default answer 
		"" buttons {"OK", "Cancel"} 
		default button 1)
	
	tell front document
		set refContexts to (every flattened context where name contains Matchstr)
		set lngContexts to count of refContexts
		if lngContexts < 1 then -- oops, didn't find any matches!
			display alert "No matching contexts found for " & Matchstr
			return
		end if
		
		repeat with curContext in refContexts
			tell curContext to 
				set {blnNotOnHold, blnHidden} to {allows next action, effectively hidden} of curContext
			
			-- CYCLE THE STATE AROUND A TRIANGLE
			-- Active --> on hold --> dropped --> active
			if blnNotOnHold then
				set {blnNotOnHold, blnHidden} to {false, false}
			else if blnHidden then
				set {blnNotOnHold, blnHidden} to {true, false}
			else -- on hold
				set {blnNotOnHold, blnHidden} to {false, true}
			end if
			
			tell curContext to 
				set {allows next action, hidden} to {blnNotOnHold, blnHidden}
		end repeat
		
	end tell
end tell