How can I set the defer date of a new created task?

Hello!

I have created a new task with the following code (works successfully):

set actionTitle to theTitle & " (Kopie)" & "@" & theContext & "::" & theProject
set newTask to (parse tasks into it with transport text actionTitle)
log(newTask)	

The result is: (task id kBCbFXSVOsZ of document id eIPIxagwE6w). And then I want to set the defer date of this task to a certain date, but this line doesn’t work:

set the defer date of newTask to theDeferDate

I get this error:
error “„«class FCDs» of {«class FCac» id “dSFgclR9X1n” of document id “eIPIxagwE6w” of application “OmniFocus”}“ can not be set as „date “Sunday, 17. January 2016 at 00:00:00”“.” number -10006 from «class FCDs» of {«class FCac» id “dSFgclR9X1n” of document id “eIPIxagwE6w”}

Can you share the portion where you set theDeferDate?

Sure it is:

tell first document window of front document
    set SelectedItemInMainView to selected trees of content
    set selectedTask to value of item 1 of SelectedItemInMainView
end tell

tell default document
    set theDeferDate to get defer date of the selectedTask
end tell

I have a script I wrote that sets the next review date, which is similar. The syntax I used there is slightly different from your method.

Edit: Clicked reply too fast. Based on that, try this:

set selectedTask's defer date to theDeferDate

Thank you for your answer. Unfortunately this doesn’t work for me.

Perhaps this is a bug? The thing is, which reference for newTask is returned when a new task is created by this line:

set newTask to (parse tasks into it with transport text actionTitle)

Only this works as a workaround, but I think the above line should also work to reference to the newly created object.

  set newTask to first flattened task where its name = theTitle

parse tasks into returns a list of the created tasks. In order to access of modify the properties of the newly created task you need to address the task itself.

try

set newTask to first item of (parse tasks into it with transport text actionTitle)

the rest of your script should then work as expected. – Sven.

1 Like