Is it possible to execute JSX scripts from outside ExtendScript?

extendscript toolkit
extendscript examples
extendscript documentation
acrobat javascript scripting guide 2018

Typically when you're writing a .jsx script to automate an Adobe product (like InDesign, Illustrator or Photoshop), you write, debug and execute the script from the ExtendScript IDE. Is it possible to bypass ExtendScript and run the script from a third program?

I think Adobe products have a built-in JavaScript interpreter which ExtendScript can connect to to access the Adobe object models and automate their software. I'd like to be able to connect directly to that interpreter and run jsx files just as I would in ExtendScript.


Are you on a Mac? If so, you can use AppleScript with the osascript tool to execute your JavaScript. Here are some examples:

Running JSX and Returning a Value

Save this as ~/temp/foo.scpt:

tell application "Adobe Illustrator"
     -- 'do javascript' runs any arbitrary JS.
     -- We're using the #include feature to run another
     -- file. (That's an Adobe extension to JS.)
     --
     -- You have to pass a full, absolute path to #include.
     --
     -- The documentation alleges that 'do javascript'
     -- can be passed an AppleScript file object, but
     -- I wasn't able to get that to work.
     do javascript "#include ~/temp/foo.jsx"
end tell

And save this as ~/temp/foo.jsx:

var doc = app.activeDocument;
var numLayers = doc.layers.length;

// The last value in the JSX file will be printed out by
// osascript. 
numLayers;

Now, from the command line run osascript ~/temp/foo.scpt It will print the number of layers in the active Illustrator document.

Getting data out of the JavaScript is limiting. You can't print to stdout from within the JavaScript. Instead, place the value you want to return as the last statement of the JSX file; it will be printed by osascript. (Here's why: The last value in the JSX file is the return value of the do javascript AppleScript statement. That is also the last value in the AppleScript file, and osascript prints the final value.)

The value you return from JavaScript can be a number, a string, an array, or anything else that retains its value when converted to a string. If you want to return a complex object, you'll need to #include a JSON library and call .toJSONString() on the object.

Passing Arguments to JSX

To pass arguments to the JSX code, follow this example:

File ~/temp/args.scpt:

on run argv
    tell application "Adobe Illustrator"
        set js to "#include '~/temp/args.jsx';" & return
        set js to js & "main(arguments);" & return
        do javascript js with arguments argv
    end tell
end run

File ~/temp/args.jsx

function main(argv) {
    var layer = app.activeDocument.activeLayer;
    app.defaultStroked = true; 
    app.defaultFilled = true;

    // Top, left, width, height (in points).
    // Note that parameters start at argv[0].
    layer.pathItems.rectangle(argv[0], argv[1], argv[2], argv[3]);
}

And then run osascript args.scpt 50 30 10 80

Debugging

The do javascript command also has options for launching the ExtendScript debugger. For details, open the Illustrator dictionary in AppleScript Editor.

Solved: Run 2019 jsx scripts from mac terminal, Solved: Is it still possible to run javascripts from mac terminal? [This post moved javascript - Is it possible to execute JSX scripts from outside ExtendScript? Change the path in do script to the path of the jsx that you want to execute. tell application "Adobe InDesign CC 2017" do script "Macintosh HD:Users:Manan:Desktop:test.jsx" language javascript. end tell. Then open command prompt and run the following command. osascript path to your applescript file. This will launch indesign and execute your


For Windows users, you can use a vbs script. Pass arguments to the .jsx script by providing arguments to the cscript command like so: cscript test.vbs "hello". test.vbs could look like so:

Dim appRef
Dim javaScriptFile
Dim argsArr()

Dim fsObj : Set fsObj = CreateObject("Scripting.FileSystemObject")
Dim jsxFile : Set jsxFile = fsObj.OpenTextFile("C:\Users\path\test.jsx", 1, False)
Dim fileContents : fileContents = jsxFile.ReadAll
jsxFile.Close
Set jsxFile = Nothing
Set fsObj = Nothing

javascriptFile = fileContents & "main(arguments);"

Set appRef = CreateObject("Illustrator.Application")

ReDim argsArr(Wscript.Arguments.length-1)

For i = 0 To Wscript.Arguments.length-1
    argsArr(i) = Wscript.Arguments(i)
Next

Wscript.Echo appRef.DoJavaScript(javascriptFile, argsArr, 1)

The Wscript.Echo will return the last line returned by the .jsx file. A .jsx file example could be:

function main(argv) {
    alert(argv[0]);
    return "test";
}

When ran, you should seee Illustrator (or whatever adobe program) alert "hello" and then "test" will be returned to stdout (you should see it in the command prompt window).

‚Äć ūü•° Is it possible to invoke a web service using the Indesign , Typically when you're writing a .jsx script to automate an Adobe product (like InDesign, Illustrator or Photoshop), you write, debug and execute the script from the¬† Est-il possible d'ex√©cuter des scripts JSX depuis ExtendScript? typiquement quand vous √©crivez un .JSX script pour automatiser un produit Adobe (comme InDesign, Illustrator ou Photoshop), vous √©crivez, d√©boguez et ex√©cutez le script √† partir de L'IDE ExtendScript.


This works in windows:

"C:\Program Files (x86)\Adobe\Adobe Photoshop CS5\Photoshop.exe" C:\completepathto\my.jsx

Pay attention to the path to Photoshop. It must be quoted since it contains spaces.

There are plenty of tricks for figuring out where Photoshop is loaded. Here is one that finds every location where Photoshop has been loaded and places those in x.lst

@REM  The Presets\Scripts doesn't really restrict where the loop is looking, 
@REM  thus the "IF EXIST" is needed.  The FIND makes sure that the 
@for /R "%ProgramFiles(x86)%\Adobe" %%f in (Presets\Scripts) 
  DO @IF EXIST %%f 
     (echo %%f | FIND /I "Adobe Photoshop C" >> x.lst )

You can then process each line in x.lst. NOTE: The entire "@for" should be on ONE line, I split it to multiple lines for readability.

If you believe there will be only one Photoshop (and not Elements) then you could change "echo %%f" to

"%%f\..\..\Photoshop.exe" C:\completepathto\my.jsx 

Can I run a JSX from KM? - Questions & Suggestions, No, there is no way (afaik) to force InDesign to call a web service from a script. This is very Is it possible to execute JSX scripts from outside ExtendScript? 0. Is it possible to execute JSX scripts from outside ExtendScript? (4) Typically when you're writing a .jsx script to automate an Adobe product (like InDesign, Illustrator or Photoshop), you write, debug and execute the script from the ExtendScript IDE.


The straight answer is YES. Illustrator, InDesign and Photoshop can all be scripted through COM. Any program that you make that can access COM (such as a .net language, C++, BCX, Autohotkey or Powerpro) can tell Illustrator, InDesign or Photoshop to do things.

Here is an example for Powerpro(you will need powerpro's com plugin), and this works in CS4 and CS5:

Function ComLoad() ;;MAKE SURE TO CALL .@ComUnload WHEN EXITING FUNCTION CALLS!
      static objname="Illustrator.Application"
      static com_status, com_type
      static appRef=com.create_object(objname)
      endfunction

Function ComUnload();;this is end the com calls and unload com
    com.unload
    endfunction

After you use the ComLoad() function, you then run any kind of method or function offered by the COM library. Here is how to use Powerpro to tell Illustrator to run your jsx or js file:

;Run a script from anywhere
Function RunOtherScript(whatscript)
    If (file.Validpath(whatscript) == 0)do
        messagebox("ok","Whoops! That script doesn't exist!","ILL Runscript")
        quit
    endif
    .@ComLoad()
    appRef.DoJavaScriptFile(whatscript)
    .@ComUnload()
    quit

Here is an image of a floating toolbar that I made using Powerpro. The buttons are all attached to com functions. Most of the time I use the com functions to run external jsx scripts.

[edit]

There is another way! You can use the Adobe Configurator to create new panels which are capable of launching scripts. You can design the panel in any way you like, and the results are quite similar in effect to the powerpro toolbar I've described above. In fact, I moved from the powerpro toolbar to an Adobe Configurator Panel.

File object, If I run the script directly from Adobe ExtendScript Toolkit it works fine in either version /3846626/is-it-possible-to-execute-jsx-scripts-from-outside-extendscript‚Äč. If I can run the .jsx script from command line, then I could just have Python make a system call to that file. But opening a .jsx script with ExtendScript just brings it into the editor and does not execute it on Windows. So perhaps associating the .jsx extension with a different .exe file could do it, but I'm not certain.


If you place the .jsx files in the right location

Photoshop
folder location:
/Applications/Adobe\ Photoshop\ CS5/Presets/Scripts
menu location:
File > Scripts

Illustrator
folder location:
/Applications/Adobe\ Illustrator\ CS5/Presets.localized/en_GB/Scripts
menu location:
File > Scripts

InDesign
folder location:
/Users/{user}/Library/Preferences/Adobe\ InDesign/Version\ 7.0/en_GB/Scripts/Scripts\ Panel
menu location:
Window > Utilities > Scripts

These are the paths on OSX, it should be easy to find the equivalent on Windows for Photoshop and Illustrator, but for InDesign it might be easier to open the Scripts Panel and open the scripts folder using the Panel's context menu.

I know that you can run .jsfl scripts from the command line by opening Flash and passing the path to the .jsfl script as an argument, but that doesn't seem to work for .jsx files with InDesign.

HTH

Overview, In Windows, a filter expression, such as "JavaScript:*.jsx;All files:*.*". Note You can use this method to run scripts, launch applications, and so on. Returns true  The ExtendScript (JSX) context is started and begins to process the request you sent it. The script you passed to ExtendScript (JSX) is processed, generating the return value you are interested in (coerces it to a string). The ExtendScript (JSX) context sends a request to process the string to the JS using the callback you specified.


Run a Sequence of Scripts in Adobe InDesign, ExtendScript script files are distinguished by the .jsx file-name extension, a variation The default is for scripts to not be allowed to write files or send or receive If you are familiar with how to run a script from the command line in Windows or  This same doJavascript() method can be used to pull in ExtendScript JSX files rather than a snippet of javscript code. You can find more details in a related SO post: Is it possible to execute JSX scripts from outside ExtendScript? look at the answers that are Windows specific.


Photoshop on Deadline? - Deadline, Javacsript offers a method for executing external scripts : doScript. function batch() { var f1 = File ( "script_1.jsx" ); var f2 = File ( "script_2.jsx" ); var f3 = File  I'm using ExtendScript Toolkit version 4.0, and using _print('foo') seems to do the trick. Is it possible to execute JSX scripts from outside ExtendScript? 0.


Extendscript toolkit 2020, But a way to launch from either the Monitor or via a command prompt would Is it possible to execute JSX scripts from outside ExtendScript? Adobe After Effects extend script - how to run the script from the command line and pass arguments? I'm trying to run an Adobe AE extendscript from the command line. I use the "-r" argument and I can run scripts fine. However, is it possible to pass in an argument to the script? Like, if i run this from the command line: C:\>"C:\P