Hi everyone,
I’m trying to write a script using the OmniFocus Automation API to access and display the creationDate
and
modificationDate
properties of the currently selected task. While these properties are visible in the
OmniFocus inspector, the script consistently returns null
or undefined
for both values.
What I’ve Tried:
-
Confirmed visibility in the Inspector:
I ensured that both "Added" (creation date) and "Changed" (modification date) fields are visible in the OmniFocus inspector for the selected task. These fields display correct values in the app.
-
Used the Automation Console:
I attempted to fetch the
creationDate
andmodificationDate
properties of the selected task using the following script:(() => { const window = document.windows[0]; const selection = window.selection.tasks;
if (selection.length === 0) { new Alert("No task selected", "Please select a task to retrieve its properties.").show(); return; } const task = selection[0]; const taskName = task.name || "N/A"; const creationDate = task.creationDate ? task.creationDate.toLocaleString() : "N/A"; const modificationDate = task.modificationDate ? task.modificationDate.toLocaleString() : "N/A"; const result = `Task Name: ${taskName}\nCreation Date: ${creationDate}\nLast Modified Date: ${modificationDate}`; new Alert("Task Properties", result).show();
})();
- Tested on multiple tasks:
I tested this script on tasks from different projects, the Inbox, and completed tasks. The output consistently shows
creationDate
andmodificationDate
asN/A
.
- Validated with other properties:
Other properties, like
name
andcontainingProject.name
, are retrieved correctly. OnlycreationDate
andmodificationDate
seem inaccessible.
- Tried AppleScript as a fallback:
Using AppleScript, I can fetch these properties without issue. However, I’d prefer a pure JavaScript solution using the Automation API.
Request for Help:
Has anyone successfully retrieved creationDate
or modificationDate
via the Automation API? Are there any known limitations or workarounds for accessing these properties?
Example Email Script:
Here’s an additional script I use for generating task reports via email, which also fails to fetch these dates:
/*{ "type": "action", "targets": ["omnifocus"], "author": "Otto Automator", "identifier": "com.omni-automation.email-task-info", "version": "1.8", "description": "This action generates an email containing detailed information about the selected task.", "label": "Send Task Info", "shortLabel": "Task Info" }*/ (() => { var action = new PlugIn.Action(function(selection, sender) { if (selection.tasks.length === 0) { new Alert("No task selected", "Please select a task to generate email information.").show(); return; }
let task = selection.tasks[0]; let taskName = task.name || "N/A"; let creationDate = task.creationDate ? task.creationDate.toLocaleString() : "N/A"; let modificationDate = task.modificationDate ? task.modificationDate.toLocaleString() : "N/A"; let note = task.note || "N/A"; let emailBody = `Task Report\n\n`; emailBody += `Task Name: ${taskName}\n`; emailBody += `Creation Date: ${creationDate}\n`; emailBody += `Last Modified Date: ${modificationDate}\n`; emailBody += `Note: ${note}`; let email = new Email(); email.subject = `Task Report: ${taskName}`; email.body = emailBody; email.generate(); }); action.validate = function(selection, sender) { return (selection.tasks.length === 1); }; return action;
})();
Any advice or insight would be highly appreciated. Thank you in advance!
Best regards,
That data I need to grab from task… and no idea how to ask system.