Can I run a JSX from KM?

I have a Javascript for using in Adobe Illustrator that I was hoping to run from within KM. Is that possible? I placed the script in an "Execute Javascript for Automation" action, but that did not work. I can run it by accessing the installed script through an Illustrator menu, but this will mean maintaining the script on multiple machines if/when KM is implemented in our production workflow. Any suggestions are welcome.

4)Save Vector PDF Script.kmmacros (4.8 KB)

I think you should be able to use the Illustrator.doJavaScript() JXA method (from inside an Execute JavaScript for Automation action) to pass your JSX source code.

Of, from an Execute Applescript action the corresponding “do JavaScript command”, but you may get into more string-escaping complexities if you do it from AppleScript.

2 Likes

3 Likes

Thank you, both.
The AppleScript worked. I do not know how to implement the "Illustrator.doJavaScript() method.

If you want to do it from a JXA action, you can pass the JSX source as a string.

The easiest approach may be to:

  1. Gather your JSX into a single (named) top level function
  2. include that function in the JXA text
  3. use JavaScript’s functionName.toString() to obtain the source code, and wrap in in ‘( … )()’ to immediately invoke the function.

I’m not near an Illustrator installation at the moment, but roughly, the JXA part of the code might look something like this:

(() => {
    'use strict';

   // JSX CODE

    function jsxCode () {
        ...
    }

    // JXA CODE
    return Application('Illustrator').doJavascript(
        '(' +  jsxCode.toString()  +  ')()'
    );

})();

Thank you. I have a lot to learn.

Cary,

I’m trying to make sense of the "Path"separators. When I copy the path directly in the Finder the folders are separated by “/”. This did not work for me initially so I changed them to “:” as shown in your sample. That worked until I moved the Javascript to a network folder. I then had to go back to the “/” separators. Any thoughts about the logic behind this?

The colon is used in HFS path. Your network folder is probably not on an HFS hard drive.

1 Like

Thanks, ComplexPoint. I will give it a try.

As I think more about this, I like the AppleScript option because that allows me to maintain the JSX in one place, while being accessed by all potential users. That’s pretty cool.

1 Like

Another solution I sometimes use is to write the JSX to a temporary file and execute this script via AppleScript


The advantage is that you can use Keyboard Maestro variables when you write your JSX.

2 Likes

@carycrusiau
I'm using the Applescript method to run a JavaScript that is saved on our server. It works except for the first time after a reboot. How do I ensure the JSX file is loaded every time?

Is the volume “LT Mac Share” automatically mounted after a reboot? If not, you should probably mount it with Keyboard Maestro before launching the script.

The volume is mounted. In fact, the folder I’m working in is on that volume.

Well, this is strange. You should try to debug your macro with Keyboard Maestro and/or debug your JSX by changing the “ignore results” of the “Execute AppleScript” action to “display result in a window”.

Well, I rebooted and this time it worked the first time. Go figure. Setting the AppleScript to “display results in a window” returns “null”. I will keep testing. Thanks for your suggestions.

I know it’s not a KM solution, but have you tried to sync your scripts with Dropbox? That’s what I do for our InDesign Scripts folder. I copy them on Dropbox, then make a Symlink in the right folder. Every user does the same thing and every time I make a change to my script, everybody gets it. That way, you run the JSX compiled by Adobe.

1 Like

Sounds like a good idea, Jeff. I’ll talk with IT and see if our Production Dept. has access to Dropbox.

The "do javascript" by way of "AppleScript" solution has been working for me until yesterday when I started testing it with AI CC 2018.

Now it works in Illustrator CC 2018, but not in CC 2015 (I change the target app in the macro). When I run it from Adobe ExtendScript Toolkit it works fine in either version of Illustrator.

I have tried running the JSX from a permanent location on the server and using the "temp" file option as suggested by carycrusiau.

If someone has an insight I'd appreciate your help.

Write or Append a File.kmactions (2.2 KB)

Why do you need to use CC2015 and 2018?

Good question.

In a high-volume production environment “if-it-ain’t-broke-don’t-fix-it” has some validity. We run numerous Illustrator actions (and soon KM Macros) on several Macs and inevitably a new software version has new bugs and does not always run the same actions smoothly.

That’s why I’ve been testing AI CC 2018 with KM, with plans to transition to it. That’s when I noticed my JSX just quit working in CC 2015. Right now, the 5 artists I will be supporting with KM Macros are still using Illustrator 2015 and I’d like the JSX macro to work properly in either software.

Sorry for the long answer.