View Single Post
Hi folks--
I've been trying to make a script that will allow me to mark projects completed from context view, since I get tired of switching over to do this. Unfortunately, something mysterious is happening: my changing of the project's completed status doesn't "take." I can successfully change the project's name or note, but not its completed status or completion date. Any thoughts? I stole the first bit of this code from the "reveal" script available here.

Code:
property toolName : "Mark Project Complete"

tell front document of application "OmniFocus"
	(* get the window the user is using *)
	set |w| to first document window whose index is 1
	tell |w|
		set theItems to selected trees of content
		
		if ((count of theItems) is 0) then
			display alert ¬
				"Select an action to " & toolName message "You have not selected an action"
			return
		end if
		
		if ((count of theItems) is greater than 1) then
			display alert ¬
				"Select just one action to " & toolName message "You have selected more than one item, please select just one"
			return
		end if
		
		set selectedItem to value of item 1 of theItems
		
		--set selectedItem to item 1 of theItems
		
		if ((class of selectedItem) is not task) then
			display alert ¬
				"Select an action to " & toolName message "You have selected something that isn't an action"
			return
		end if
		
	end tell
	set P to containing project of selectedItem
	if (P is missing value) then
		display alert ¬
			"Select an action to " & toolName message "You can't mark the inbox complete!"
		return
	else
		(* a real project, not the inbox *)
		tell application "OmniFocus"
			set note of P to "Kilroy was here" --this works
			set completed of P to true
			set displaytext to completed of P as rich text
			set completion date of P to current date
			set displaytext to displaytext & " " & completion date of P as rich text
			display dialog displaytext --shows "false" and "no value"
		end tell
	end if
end tell