I use the following Apple script to do the same thing, which works perfectly.
tell application "OmniFocus"
tell default document
set flaggedTasks to every flattened task whose flagged is true and completed is false
repeat with a from 1 to length of flaggedTasks
set currentTask to item a of flaggedTasks
set taskName to name of currentTask
set taskID to id of currentTask
end repeat
end tell
end tell
But the following JXA doesn’t work at all, it just returns to nothing. Just don’t understand what’s wrong with this JXA.
var app = Application.currentApplication();
app.includeStandardAdditions = true;
var omniFocus = Application("OmniFocus");
var defaultDocument = omniFocus.defaultDocument;
var flaggedTasks = defaultDocument.flattenedTasks.whose({flagged: true, completed: false});
for (var i = 0; i < flaggedTasks.length; i++) {
var currentTask = flaggedTasks[i];
var taskName = currentTask.name();
var taskID = currentTask.id();
}
If i want to get all flagged tasks using OmniAutomation rather than JXA in an external script, what should I do next, because I’m not very familiar with OmniAutomation API and I guess that can be kind of different from JXA.
Thank you so much! And could you please give me some further instructions on how to get all tasks with a certain tag (like ‘morning’, ‘afternoon’, or ‘evening’), and how to get all tasks with the due date of today?
(Just because I’m building a little plugin to send all the tasks which have a tag of ‘morning’, ‘afternoon’ or ‘evening’, is due today, or is flagged to Habitica, I have finished other parts, including making HTTP requests, but I’m just not very familiar with Omni Automation API)
Actually, after making several attempts, I’ve found out how to do with the tag, I know Tag.byIndentifier(${identifier}).tasks should work, however, I just wonder if there exist other ways, for example, to get the tags by name, so that I can get the tasks with all the tags I would like more easily.