Apple Event Error with OmniFocus Task

Hi everybody.

I want to begin scripting Omnifocus.
I want to create a new task.
This is just an example.

tell application "OmniFocus"
	launch
	set nombre to "Prueba tarea"
	set descripcion to "Esta es la descripción de la nota"
	set fecha to current date
	tell default document
		make new task with properties {name:nombre, note:descripcion, defer date:fecha}
	end tell
end tell

If I take a look to the Event Log, it throws and error with current date (Err -10004: A privilege violation occurred), and and error with the creation of the task (Err -10000: The Apple Event handler failed)

In spite of the errors , the task is created in the inbox.
¿What has happened?

Have a nice weekend and thanks for your time.

I don’t have OmniFocus, however I can tell you what’s causing the privilege violation error: you are using current date, which is a scripting addition command, inside an application tell block. That generates an error, and then redirects the command directly to the addition.

1 Like

Thanks Shane!

With your answer, now the first error is solved.
I have taken out of the tell block the offending line (current date).

set fecha to current date
set nombre to "Prueba tarea"
set descripcion to "Esta es la descripción de la nota"

tell application "OmniFocus"
	launch
	tell default document
		make new task with properties {name:nombre, note:descripcion, defer date:fecha}
	end tell
end tell

But when the task is created (and in fact, the task is created in the Omnifocus´ inbox) the Apple Event handler continues to throw Error -10000.

Does anybody know the reason?

Hi Alberto,

I think the error may be that you’re not telling it where to make the task, I found an example on Omni’s website and played around with your script until I got it to work.

The only change is the addition of inbox before task

set fecha to current date
set nombre to "Prueba tarea"
set descripcion to "Esta es la descripción de la nota"

tell application "OmniFocus"
	tell default document
		make new inbox task with properties {name:nombre, note:descripcion, defer date:fecha}
	end tell
end tell

Regards Alan

1 Like