VSCode doesn't know anything about Automation objects, because they're not defined in your source file, so you won't get code completion on them. If someone wanted to take the time and effort to create an Intellisense JSON file for Automation objects, then you'd have it, but I don't see that happening.
I installed CodeRunner and also AppleScript extension
Which is good, but they don't have anything to do with code completion. Well, that's not entirely true. The AppleScript extension gives some support for Intellisense with the AppleScript language mode, but that doesn't help with JXA.
And when I try and type the code that you have in your example, this is what I get.
Regarding Intellisense for Automation objects, someone has created something for TypeScript/Node.js that has Intellisense definitions for JXA, but I have absolutely no idea how to use it. So don't ask me. But if you figure it out, feel free to post it here.
So I guess as far as the setup of VSCode and running JXA files (saved as js files) using Code Runner, I am all set. Thank you! I know it is repetitive, but so be it.
From an earlier message of yours - so say I create myApp like so var myApp = Applications("Keyboard Maestro"). Is there a way to inspect myApp in Safari console? I tried console.log() and JSON.stringify(). Neither seem to work. Nor does console.dir() which Safari reports is not even a function.
Thank you for the link. Yes will go through the scripts that you created. And I know what you mean that one does not want to look at one's own old code.
Quick question on how you do the above. So where do you use console.log or JSON.stringify() to look at what inspect JXA objects?
This is the big issue that I am facing right now. Perhaps I need to start another thread and ask as to how to best interpret and use the Dictionary in Script Editor. May be, if I can interpret the dictionary better, then I will feel less need to inspect JXA objects...
I totally, 100% agree with how frustrating it is. If you go back a few years you'll find some posts from me, where I'm, um, "complaining" to anyone who'll listen about why is this so hard to figure out?
As far as I know, you can't use console.log() to find out the properties of Automation objects.
As for how to use the dictionary, it's easy, if not a little frustrating.
Start Script Editor, and click the "New Document" button in the bottom left.
Click "File->Open Dictionary".
Select the application, like "Keyboard Maestro Engine".
Then you have to start looking around, but for the KM Engine, try clicking on the "Keyboard Maestro Engine Suite", and in the second column, you'll see some of the functions and objects available.
I'm pretty sure @JMichaelTX has a bunch of resources listed somewhere, too.
My best advice: Get frustrated, don't get frustrated, either way, don't give up. If it happens to you like it happened to me, one day you'll want to tear your hair out, and the next day it suddenly starts to click.
Thanks for the encouraging words and the help and the links. At this point, I am trying to Automate some things with OmniFocus app. The Script Dictionary concepts that I need to understand are basic concepts however.
I am guessing it is best to start another thread for that.
Got this. However, can this be used on JXA objects? That does not seem to work for me.
So, when running a JXA script which is in debugger mode and in Safari debugger and halted,
then after running myApp = Application("Keyboard Maestro");,
executing JSON.stringify(myApp); in the Safari console results in undefined as output, and console.log(JSON.stringify(myApp)); does not generate any information either.
I followed the steps he listed, and I'll add a couple of notes:
I created a folder called Test (not totally relevant, but it's what I did).
Opened a Terminal window inside the Test folder.
I executed the first step from the above "example" link: git clone https://github.com/JXA-userland/editor-integrate-example
It worked, and created a subfolder called editor-integrate-example with some stuff in it.
Next step from link: cd editor-integrate-example
Next step: npm install
This failed with a bizarre error because my node or npm installation(s) were messed up (I don't know a lot about this stuff), but some searches led me to this solution, which worked because fortunately, my installation of homebrew is NOT messed up:
Next step: vscode .
But it couldn't find vscode, so I must not have my path set correctly for VSCode from the command line. So I did it this way:
Opened VSCode the normal way, then:
File->Add folder to workspace
Added the folder that had been created in my Test folder, editor-integrate-example.
Opened the file example-jxa.js.
Hovered my cursor over the Application object, and presto! Intellisense! It looks kind of different, but there's certainly good info there.
Here's some thoughts:
Either package.json or tsconfig.json are probably what's telling VSCode where to get the Intellisense files. I'm guessing it's package.json because I think the other one is for TypeScript.
I have no idea where to put this stuff so it's accessed automatically from other JXA projects.
No Intellisense for any other applications, like "Keyboard Maestro", etc. However, if you delve into the source files, I can't believe he typed them all by hand, so I'm guessing there's a way to import a Dictionary entry to create these files. If so, then someone could create them for "Keyboard Maestro", etc. But I don't have the time to spend on it now, so it's up to you guys, or nobody. I've got a video I have to finish, and then some "honey-do" projects, so that's as much time as I can spend on this. I'm telling myself this, also.
Q. Is there any benefit of running the script in script editor - I am sure there is and I do not know? Especially if one is using debugger; to debug the script - not that I have used the safar debugger lately - will try to use now?