The Omni Group Forums

The Omni Group Forums (http://forums.omnigroup.com/index.php)
-   OmniFocus Extras (http://forums.omnigroup.com/forumdisplay.php?f=44)
-   -   Deleting estimated time from script? (http://forums.omnigroup.com/showthread.php?t=22441)

treyharris 2011-10-22 02:10 PM

Deleting estimated time from script?
 
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:

[CODE]
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
else
set estimated minutes of mainTask to missing value
end if
end using terms from
end toggleTask
[/CODE]

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 [FONT="Courier New"]if estimatedMins is missing value[/FONT] to [FONT="Courier New"]if estimatedMins is 0 or estimatedMins is missing value[/FONT], 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 [FONT="Courier New"]delete (estimated minutes of mainTask)[/FONT] and [FONT="Courier New"]set estimated minutes of mainTask to ""[/FONT], 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!)

whpalmer4 2011-10-22 06:35 PM

It wouldn't be the first bug in their applescript implementation...from my reading of the dictionary, setting the value to missing value ought to put it back to not having any estimated duration, but I agree that that often isn't the result obtained. Use Help->Send Feedback to file a bug report.


All times are GMT -8. The time now is 10:09 AM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2019, vBulletin Solutions, Inc.