Thanks! That does help showing me that I can return a list of task IDs to Keyboard Maestro which is kinda what I want but my starting point was to run some test code from the omniJS console but then later call it from Keyboard Maestro to get the results into a KM variable
The way to go about this seems elusive to me but I can run this from the omni console and get almost what I want I just don’t know how to “return the task ID” back to Keyboard Maestro
Here’s a script I’m trying to adapt to return what it finds to KM, I can run it from the omni automation console
var win = document.windows[0]
var tasks = win.selection.tasks
tasks.forEach(task => {
console.log(“->”, task.name)
console.log(“parent w/tags: “, task.tags)
var doneTag = flattenedTags.byName(“✅”)
if (task.hasChildren){
task.children.forEach(task => {
console.log(” → “, task.name)
console.log(” kid w/tags: “, task.tags)
task.tags.forEach(tag => {
if (tag.name == “✅”){
console.log(“FOUND DONE”, task.tags)
console.log(” parent”, task.parent)
console.log(" ID of kid", task.id.primaryKey)
//open(“omnifocus:///task/hSXeRoGYJAg”)
}
}
)})}})
In the above with the selection I’m testing with I know I can get a task ID that I will want to save and use open URL from another macro later. But not sure how I can “return” the taskID to KM. I can percent encode this and run either
omnifocus:///omnijs-run?script=%omni JS encoded%
omnifocus://x-callback-url/omnijs-run?script=% omni JS encoded%
to invoke the script and have it do what I want.
I can also use xcallback.app from within KM
/Applications/xcall.app/Contents/MacOS/xcall -url "omnifocus://x-callback-url/omnijs-run?script=%omni JS encoded%
and save results from that but again I still can’t get the task ID to “be returned”
I tried to mess with setting and getting KM variables from within the code I send to OmniFocus but I can’t seem to use
var app = Application.currentApplication()
app.includeStandardAdditions = true
var kme = Application(“Keyboard Maestro Engine”);
var foundTaskID = “omnifocus:///task/” foundTaskID;
kme.setvariable(“task_to_open_later”, { to: foundTaskID });
but from what I can see the omniJS console doesn’t have “Application” so I can’t get that context to us the KM JXA API to get and set KM variables