Visual Studio Code (VSC) Now Supports JXA Scripts

It is too bad that VSC does not support JXA, as least as far as I can tell.
That is very cool with Docker and MS-SQL Server. Back in the day I used to do a lot of SQLServer work, but these days no Windows work at all. Yeah!


EDIT: See below

Well… it might… https://marketplace.visualstudio.com/items?itemName=idleberg.applescript

I haven’t tried that but it could be interesting.

Thanks for sharing that – it looks very interesting.
This will be awesome if it works well for JXA.

I just installed and tried the JXA extension for VSC, and at first pass it seems to work well.

Note that the extension is named “AppleScript” because it also supports AppleScript. But all you need to do is save a file with a .jxa extension and VSC will auto-recognize it as a JSA script.

To compile and run JXA scripts, open the Command Palette with ⌘⇧P, and type “JXA” to see the choices for it. Or, just use these shortcuts:

  • JXA: Run Script – Shift+Opt+R
  • JXA: Compile Script – Shift+Opt+B

This is huge IMO. I understand that Atom will support the JXA syntax, but I’m not sure if it will compile/run the script directly in Atom.

My next step will be to determine if we can run the VSC debugger with a JXA script.

Please feel free to post your questions, issues, and suggestions below concerning JXA in VSC.

1 Like

Creating .scpt File from .jxa File

Good news. When you compile/run the .jxa file in VSC, it automatically creates a companion .scpt file, which you will need if you want to run the file from a KM Execute JXA from a file, or via FastScripts.

image

Opening a .scpt File in VSC

Short answer is you can’t. You will need to save a text file with a .jxa extension.

I’ll work on a macro/script to do that.

Even better, you can change the shortcuts to whatever you like.
I prefer the shortcuts used by both Script Editor and Script Debugger:

JXA: Run Script – ⌘R
JXA: Compile Script – ⌘K

See Key Bindings for Visual Studio Code

2 Likes

I’m late to the VSC discussion, but I’m proud of you for doing so much for jxa and vsc for the community. When I search Google for info, your name is almost always involved in the results, For anyone who thinks one person can’t make a difference, search for “vsc jxa” and look at the results. Way to go, Jim!

So, as you know, I’ve been using Atom for jxa development for quite some time. Suppose I wanted to switch to VSC? Can you offer guidelines for installing VSC and getting it up and running for JXA? If you already posted this info, just point me to it.

Thanks!

Dan, its great to see you back in the SW dev game. Really missed your great stuff and our collaboration.

I don't have a great set of guidelines, but you might start here:

It has now been at least a year since I was really active with JXA and VSC.
I was not super happy with the JXA integration, and had some issues getting it to run properly. About that time I became involved in the SD beta, and soon had a copy of SD7. SD7 offers such a great IDE for AppleScript that you really can't get with JXA, that now days most of my development is in AppleScript.

There have been a few exceptions.

If you do get JXA working well with VSC, please let me know, and that would be a huge motivator for me to return to JXA. The JavaScript autocompletion offered by VSC is terrific, and if it can be made to work for JXA (app objects, etc) then that would be best of all worlds.

Thanks for the reply, Jim. I miss the fun and "discussions" we had in the past. But I'm so busy with the YouTube channel that I probably won't do much with VSC. If it's not working really well right off the bat, then I have no reason to change from Atom. I'm mostly just editing existing JXA, or copying something and modifying it for another purpose.

Dan