Keyboard shortcuts for setting due dates?

@unlocked2412 First of all thank you for sharing your scripts and making them to help us. This is a script I would like to use and ideally also understand how to modify.

In that context, have a few basic JXA related questions, if you can comment on.

Q1.
How do you decide when to create a const, and when to access the contained object using dot notation.
For example:

const of = Application('OmniFocus');
	const oDoc = of.defaultDocument;
	const oWin = oDoc.documentWindows[0];
	const seln = oWin.content.selectedTrees.value();

vs say this below

    const of = Application('OmniFocus');
    const seln = of.defaultDocument.documentWindows[0].content.selectedTrees.value()

Q2.
What IDE do you use to code and debug JXA scripts?

Q3. How can one inspect the seln array that gets created, or inspect of received from of = Application("OmniFocus")? In say the Safari debugger console that I am able to access while running the script that you shared. I have tried console.log, JSON.stringify(of). Nothing reveals anything. I think I am doing something conceptually incorrect.

Thank you.

Glad you found the scripts useful. Far from my desk now, will answer properly to your questions tomorrow in the evening.

1 Like

In my personal case, if I am going to access several properties of a certain object, I save it in a variable once and get its properties via dot notation. Example:

const of = Application('OmniFocus');
const oDoc = of.defaultDocument;
const oWin = oDoc.documentWindows[0];

Now, I can access .id, .name and .visible with oWin.id(), oWin.name() and oWin.visible().

Perhaps, code readability would be another factor.

Atom with these packages installed.


If you run this code in Script Editor (with language tab set to JavaScript), it’s possible to inspect the array in the Result pane.

(() => {
	const of = Application('OmniFocus');
	const oDoc = of.defaultDocument;
	const oWin = oDoc.documentWindows[0];
	const seln = oWin.content.selectedTrees.value();
    return seln;
})()

Or, if you want to map the array of objects into an array of task names, you can do it with this line:

return seln.map(x => x.name())

Adding debugger; to the top of your code would enable the Safari Debugger for JS Contexts.

1 Like

Thank you for the reply. Very helpful.

Quick followup: seln.map(x => x.name()) is great and can be executed in the Safari debugger console also.
Can one also see what kind of object seln is while in Safari debugger? If not that is ok.

Thanks again!

You’re welcome.

Sure, it’s posible. As seln is a collection of objects, you can, for example, inspect the properties of the first element of that collection (assuming there is at least one element selected), saving its properties in a variable.

(() => {
	const of = Application('OmniFocus');
	const oDoc = of.defaultDocument;
	const oWin = oDoc.documentWindows[0];
	const seln = oWin.content.selectedTrees.value();
    const treeProperties = seln[0].properties()

    debugger;
    return seln;
})()

Thank you! Sounds great.

1 Like

Addressing your specific question, when we try to see what kind of object seln is in the Debugger, we see it is an Array of ObjectSpecifier, but we can’t see (as far as I know) exactly what the properties of each element are. That’s why I suggested inspecting an specific element of it.

That makes sense.

I am new to programming and seeing how one can dive into almost any object in the python debugger that VS Code makes available, was expecting something similar here also…

Script Debugger enables great level of detail in terms of object properties exploration. Only AppleScript is supported, though. Helped me familiarize with the OmniFocus object model.

I have not purchased the software and the price is a bit high for my likely usage level and the desire to tinker with JXA.

Sounds like object property exploration is far better than Script Editor and sounds like it will give me a better understanding of the object model.

And it sounds like understanding the Apple Script object model will help because the model is more or less same for JXA also.

guess the brief question is whether it is worth buying SD7 to use its object model explorer (of which I just saw a video on YouTube) to then use it in a JXA script. :)

Version 7 has a Lite mode, but it doesn’t have live explorer. Perhaps worth a try.

It is exactly the same. The main difference is in the syntax (as JS is a completely different language. Other differences relate to how files are represented. For example, in JavaScript, file and folder paths are represented using Path objects. You can see a comparison here:

Mac Automation Scripting Guide

The enormous advantage of having all array methods of ES6 JS built-in like map, filter and reduce is very welcomed.

Nowadays, I code in AppleScript very rarely but SD proved very useful for understanding OF (and other scriptable apps) object model. Getting accustomed to it takes some times.

I think those skills are transferrable with the obvious adaptation to the JS idiosyncrasy I mentioned above.

Thanks for the reply. Will read through the link you shared.

Sounds like no other way to do something like the live explorer. Is there?

That is why I do not want to use AppleScript and learning javascript is a side objective as much. Good to hear that you have moved to JXA for the same reasons.

It’s the only option, as far as I know. Would be good if Late Night Software releases a version of SD with JXA support, but that seems highly unlikely.

Ok. So need to ponder over whether worth it for just the live object exploration for hobby tinkering, the value of which tinkering is somewhat dubious :)

Big thank you again for the hand holding here. Have a wonderful day.