Unable to Access creationDate and modificationDate via OmniFocus Automation API

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:

  1. 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.

  2. Used the Automation Console:

    I attempted to fetch the creationDate and modificationDate 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();
    

    })();



  3. Tested on multiple tasks:

    I tested this script on tasks from different projects, the Inbox, and completed tasks. The output consistently shows creationDate and modificationDate as N/A.



  4. Validated with other properties:

    Other properties, like name and containingProject.name, are retrieved correctly. Only creationDate and modificationDate seem inaccessible.



  5. 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.

Sorry this wasn’t more obvious! Those two properties are called task.added and task.modified.

You can find the documentation for Task’s properties by opening Automation > API Reference and using the sidebar to open the API documentation for Task. The tricky thing here is that those two properties aren’t actually listed under Task itself, so you won’t see them listed there directly. Instead, you’ll see (in the header) that Task is a subclass of ActiveObject, which is a subclass of DatedObject. That’s where you’ll find the documentation for the added and modified properties:

DatedObject : DatabaseObject

Instance Properties

var addedDate or null### var addedDate or null

Returns the date the object was first saved. If the object is newly inserted, this will be null. For newly inserted objects, the added property may be set (but once an object is saved for the first time, the property is read-only).

var modifiedDate or null

Returns the date the object was most recently modified. If the object is newly inserted, this will be null. For newly inserted objects, the modified property may be set (but once an object is saved for the first time, the property is read-only).

(The reason they’re listed under DatedObject is because they apply to a number of types of objects stored in the database: not just Task, but also Folder, Tag, Perspective.Custom, and Task.Notification.)

Hope this helps!

2 Likes

FYI - for an additional reference see lines 116 and 117 of javascript automation that copies out a set of selected OF tasks to Obsidian that captures the creation and modification dates in addition to tags and notes: A modified version of https://omni-automation.com/omnifocus/plug-in-obsidian.html that supports copying all selected notes and not just one · GitHub

Thank you, it works and I have all data.