Can I run a JSX from KM?

Your problem is just the target app then?

If I understand what you mean, yes. When I target CC 2015 in the KM Macro, the called JSX script does not run. If I call CC 2018 it works fine. If I run the script directly from Adobe ExtendScript Toolkit it works fine in either version of Illustrator.

Where exactly do you target in KM?

I'm using the "Open Finder Selection in…" action in KM to target the illustrator app and use the pulldown menu to select the version I want.

Is your group correctly targeted?

What “Group”?

Your macros are inevitably in a group (first column on the left in KM) and each group is targeted. The macros in my "Adobe Illustrator" group are only available in Adobe Illustrator CC 2017.

image

image

I could try explicitly targeting CC 2015

Does the Finder selection open in the Illustrator of your choice?

Are the 2 Illustrator versions opened simultaneously?

Yes. It just goes no further, now, in CC 2015.

If the 2 Illustrator versions are open simultaneously, then I suppose it’s due to the AppleScript command tell application “Adobe Illustrator”. The Illustrator version is not specified in the command. How can AppleScript know which Illustrator to work with? So I suppose AppleScript try to execute the script in the last version and not in 2015.

Try to quit 2017, run only 2015 and execute your macros.

I’ve tried that. It does not fix the problem. I am planning to test it on another computer today. I just have to wait for the right window of time.

I will let you know what the results are.

I sure appreciate your help, Cary.

rcraighead, don't know if it's relevant, but I think KM supports Apple's version of Javascript as opposed to Adobe's version, but I might be wrong on that.

1 Like

See https://stackoverflow.com/questions/3846626/is-it-possible-to-execute-jsx-scripts-from-outside-extendscript

From KM you can do it from inside Execute Shell Script, Applescript or Javascript actions.

(Assuming that you have the relevant Adobe application installed)

1 Like

To remove the need for any special quoting of the JSX code string, I would personally tend to make use of the fact that any Javascript function can be converted to its code string at run-time by using the .toString() method.

The means that inside a KM Execute a Javascript for Automation action, we could write something like this:

(() => {
    'use strict';

    // A JSX JS function which we will convert to a string
    const jsxFunction = () => {
        let doc = app.activeDocument;
        let numLayers = doc.layers.length;
        return numLayers;
    };

    // Invoking .doJavascript(CodeString) from JXA JS
    return Application('Adobe Illustrator')
        .documents.at(0).doJavascript(
            jsxFunction.toString()
        );

})();

This means that we are using two different JS interpreters:

  • JXA to prepare a string version of the JSX function and submit it to Illustrator, and
  • JSX embedded in Illustrator to perform the evaluation of that code string.

oooookkkk, that's above my pay grade;-)
Man I need to learn javascript...

1 Like

Ver 3 of this is free and online.

https://eloquentjavascript.net/

I think it's quite good.

Thanks @ComplexPoint, I'll have a look.