How To Use "VS Code" for JXA, with Keyboard Maestro

The main reason is to use the Safari Debugger.
This is the ONLY debugger I know of for JXA.

Also, the SE log pane (at the bottom) provides more output than simply console.log(). If there is a better way, with better output solely using VSC I am open to that.

Bingo❗ Found a converter:

Convert Scripting definition files (.sdefs) to TypeScript(d.ts) -- GitHub JXA-userland

I am such a novice at Terminal and VSC that I don't understand how to use this tool. It looks like it offers a script that can be run from VSC, but I don't understand how. Maybe one of you VSC gurus can figure this out:

From the GitHub

Install with npm:

npm install @jxa/sdef-to-dts

Usage as library
Convert ./input/*.sdef file and output it as d.ts to ./output directory.

const fs = require("fs");
const path = require("path");
const { transform } = require("@jxa/sdef-to-dts");
const sdefDir = path.join(__dirname, "./input");
const outputDir = path.join(__dirname, "./output");
const promises = fs.readdirSync(sdefDir).map(async caseName => {
    const fileName = path.basename(caseName, ".sdef");
    const normalizedTestName = fileName.replace(/\s/g, "");
    const actualContent = fs.readFileSync(path.join(fixturesDir, caseName), "utf-8");
    console.log("transform " + normalizedTestName);
    const actual = await transform(normalizedTestName, actualContent);
    fs.writeFileSync(path.join(outputDir, normalizedTestName) + ".d.ts", actual, "utf-8");
});
Promise.all(promises).then(() => {
    console.log("All write");
});

How do we use as "library" to convert .sdef files (actually the .app file)???

Oh. I did not realize that Safari Debugger cannot be invoked from JXA using Code Runner. In that case, it makes most sense to try and use the .scpt route that you found and marry VS Code, SE and KBM. Very creative solution. Will work on adopting it.

@DanThomas @sims, @ccstone, @ComplexPoint et al:

I have just posted a macro and video:

MACRO: Run Current VSC JXA Script in Script Editor

My sincere thanks to everyone who has helped us all understand how to use VSC to develop JXA.

1 Like

3 posts were split to a new topic: Problems with KMFAM Macro System

I am wondering if Keyboard Maestro can plug into the text cursor position within VSCode.

I think you would probably need to explore the VSC extension API:

Your First Extension | Visual Studio Code Extension API

1 Like

In a word – nyet.

@ComplexPoint's idea is intriguing, athough I don't know of any way to run external code in VSC and return a result.

Worth a peek:

visual studio code - vscode API: get Position of last character of line - Stack Overflow

-Chris

I think that's right – the obvious route would be to do the whole thing from inside the VSC extension.