The Omni Group Forums

The Omni Group Forums (http://forums.omnigroup.com/index.php)
-   OmniFocus Extras (http://forums.omnigroup.com/forumdisplay.php?f=44)
-   -   due date format (http://forums.omnigroup.com/showthread.php?t=25051)

kappamia 2012-07-30 06:52 PM

due date format
 
I want to write a script like this:
[PHP]
tell application "OmniFocus"
tell default document
set Val1 to "foo"
make new inbox task with properties {name:Val1, due date:"1d"}
make new inbox task with properties {name:Val1, due date:"3d"}
make new inbox task with properties {name:Val1, due date:"7d"}
end tell
end tell
[/PHP]

but, I got error: "error "OmniFocus got an error: Can’t make \"1d\" into type date, missing value." number -1700 from "1d"".

I need help...

whpalmer4 2012-07-30 08:54 PM

You're asking Applescript to know how OmniFocus interprets date strings, which isn't a reasonable request. It isn't difficult to code it up yourself, but why do a bunch of work to emulate what the program will do for you? An easier route would be to use the parse tasks construct.

[code]
tell application "OmniFocus"
tell default document
set Val1 to "foo"
set Date1 to "# 1d"
set Date2 to "# 3d"
set Date3 to "# 7d"
set Task1 to parse tasks with transport text Val1 & Date1
set Task2 to parse tasks with transport text Val1 & Date2
set Task3 to parse tasks with transport text Val1 & Date3
end tell
end tell

[/code]

See the built-in help for "Processing mail messages into actions" for details on the format to use.

RobTrew 2012-07-31 09:02 AM

[I]whpalmer4[/I]'s approach is much the most flexible and powerful. The nearest thing to your first draft that AS itself could understand would be along the lines of:

[CODE]tell application "OmniFocus"
tell default document
set Val1 to "foo"
set dteNow to current date
make new inbox task with properties {name:Val1, due date:dteNow + 1 * days}
make new inbox task with properties {name:Val1, due date:dteNow + 3 * days}
make new inbox task with properties {name:Val1, due date:dteNow + 7 * days}
end tell
end tell[/CODE]

RobTrew 2012-07-31 01:03 PM

And of course, as [I]whpalmer4[/I] reminds me, it's not quite a simple as that, because you probably want the tasks to have the default due date time, as specified in OF preferences.

By the time you have looked for a way of doing this, the advantages of the [I]parse tasks[/I] approach are beginning to be quite clear :-)

[CODE]tell application "OmniFocus"
tell default document
set Val1 to "foo5"

set dteBase to (current date)
set dteBase to dteBase - (time of dteBase) + (my GetDefaultDueTime())

make new inbox task with properties {name:Val1, due date:dteBase + 1 * days}
make new inbox task with properties {name:Val1, due date:dteBase + 3 * days}
make new inbox task with properties {name:Val1, due date:dteBase + 7 * days}
end tell
end tell

on GetDefaultDueTime()
tell application id "OFOC"
tell default document
set dteBase to current date
set dteBase to dteBase - (time of dteBase)
return (my date (short date string of dteBase & space & (value of setting id "DefaultDueTime"))) - dteBase
end tell
end tell
end GetDefaultDueTime[/CODE]

kappamia 2012-07-31 05:50 PM

thank you guys
 
Thanks very much.
These are exactly what I want!


All times are GMT -8. The time now is 10:17 PM.

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