Reputation: 107
I'm trying to implement automation for the task manager Things 3 on macOS using JXA (Javascript for macOS automation) and I'm running it to a strange error. I have spent countless hours trying to fix this myself and with the help of others. I am trying to use the following method described in the documentation:
As following:
// Set TaskApp as the app to use
var TaskApp = Application('Things3');
// Get the ToDo from toDos
var task = TaskApp.toDos["test555342343"]
// Get today as a date
var today = new Date()
// Schedule the task for Today
task.schedule(task.id(), {for: today})
This returns the error:
Error: Error: Named parameters must be passed as an object.
When using another method (like show
) the specefier works as expected:
Example:
// Set TaskApp as the app to use
var TaskApp = Application('Things3');
// Get the ToDo from toDos
var task = TaskApp.toDos["test555342343"]
// Bring Things3 to the Forground
TaskApp.activate()
// Show the task
task.show(task.id())
Will show the selected todo. Creating a task with with a deadline set to the date
object also produces the correct result (a task with the deadline of date
).
This documentation can only be found when you have things3 installed on macOS and you reference the Script Library. I have added the documentation as PDF. The described error also apply's to the move
method. Instead of parsing a date you parse a List Object
to it which will resolve in the same error.
Link to documentation PDF → Link
Upvotes: 2
Views: 467
Reputation: 3413
The Things documentation is wrong: schedule
is a method of Application
, not of ToDo
, which is why it asks for a todo specifier (it wouldn’t need that one if it was a property of a ToDo object already). The working code hence is:
// Set TaskApp as the app to use
var TaskApp = Application('Things3')
// Get the ToDo from toDos
var task = TaskApp.toDos["test555342343"]
// Get today as a date
var today = new Date()
// Schedule the task for Today
TaskApp.schedule(task, {for: today})
Note that task
already is a ToDo specifier; you don’t need the detour through task.id()
, which converts the ToDo specifier into an ID String before letting the schedule
method cast that back to a specifier.
Upvotes: 2