@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 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.
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:
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.
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.
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.
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.
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:
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.