View Single Post
I'm having trouble figuring out how to delete the estimated time from a script.

Say I wanted to write a script that would toggle the estimated time of the current task from nothing to something and back. One might think I could write:

property newTimeEstimate : 3 -- minutes

tell application "OmniFocus"
	set theDoc to document window 1 of document 1
	set selectedTask to the value of the first item of the selected tree of the content of theDoc
	tell me to toggleTask(selectedTask)
end tell

on toggleTask(mainTask)
	using terms from application "OmniFocus"
		set estimatedMins to estimated minutes of mainTask
		if estimatedMins is missing value then
			set estimated minutes of mainTask to newTimeEstimate
			set estimated minutes of mainTask to missing value
		end if
	end using terms from
end toggleTask
If you run this script on a task with no estimated time, it sets the time to 3m, as expected. Unfortunately, if you run it again, rather than removing the estimated time, it sets it to 0m. "missing value" doesn't match "0m", so the script doesn't actually toggle; it goes nothing → 3m → 0m.

Of course, in this contrived script, I could just change if estimatedMins is missing value to if estimatedMins is 0 or estimatedMins is missing value, and that would make it work, but for my larger problem, its possible that some items might actually have an existing estimated time of 0, and I need to differentiate them from ones that have no estimated value set at all. (Also, the "Unestimated" filter does not match 0m, only the unset value.)

I've tried delete (estimated minutes of mainTask) and set estimated minutes of mainTask to "", and these do not work.

Apologies if the answer is obviousómy AppleScript isn't great. (It looks like the Python, Ruby and Perl interfaces to OmniFocus I see floating around on the web all bridge through AppleScript, so I haven't tried any of these, but if I'm wrong and one of them is a first-class API, by all means let me know, since I'd rather not struggle with a language I'm unfamiliar with!)