From 2ca3e48719a6fabd070891dc2fa30ae7015d9c4a Mon Sep 17 00:00:00 2001 From: thaodangspace Date: Wed, 26 Aug 2026 09:44:42 +0700 Subject: [PATCH] Fix ToDo creation in JXA automation Replace app.make({ new: "to do" }) with app.ToDo(...) pushed directly into target containers (inbox or project). This avoids "Can't make class" errors on macOS/Things versions where the two-word "to do" class specifier fails to resolve. --- things/automation.js | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/things/automation.js b/things/automation.js index f586ce2..fcae48a 100644 --- a/things/automation.js +++ b/things/automation.js @@ -747,6 +747,16 @@ function deleteRelation(object, property) { relation.delete(); } +// Things' JXA `make({ new: "to do" })` throws "Can't make class" on some +// macOS/Things builds (the two-word "to do" class does not resolve), so build +// the ToDo object and push it into a container instead -- the form Things +// reliably accepts. `container` is a project or one of app.lists (e.g. Inbox). +function newTodo(app, container, title) { + var task = app.ToDo({ name: title }); + container.toDos.push(task); + return task; +} + function addTodo(app, request) { if (request.completed && request.canceled) throw new Error("completed and canceled cannot both be true"); if ((request.list || request.list_id) && (request.project || request.project_id)) { @@ -756,10 +766,9 @@ function addTodo(app, request) { var task; if (request.project || request.project_id) { project = resolveProjectTarget(app, request.project_id, request.project); - task = app.ToDo({ name: request.title }); - project.toDos.push(task); + task = newTodo(app, project, request.title); } else { - task = app.make({ new: "to do", withProperties: { name: request.title } }); + task = newTodo(app, resolveListTarget(app, "", "Inbox"), request.title); } applyCommonFields(app, task, request); if (!project) applyListDestination(app, task, request); @@ -775,12 +784,7 @@ function addProject(app, request) { if (request.area || request.area_id) project.area = resolveAreaTarget(app, request.area_id, request.area); var children = request.to_dos || []; for (var i = 0; i < children.length; i++) { - var child = app.make({ new: "to do", withProperties: { name: children[i] } }); - try { - child.project = project; - } catch (error) { - app.move(child, { to: project }); - } + newTodo(app, project, children[i]); } if (request.reveal) project.show(); return actionResult("add-project", project);