Skip to main content
Participant
February 6, 2019
Answered

Run 2019 jsx scripts from mac terminal

  • February 6, 2019
  • 3 replies
  • 6417 views

Is it still possible to run javascripts from mac terminal?

[This post moved from InDesign to InDesign Scripting by Moderator]

This topic has been closed for replies.
Correct answer Manan Joshi

Hi Ibrahim,

You might wanna investigate osascript on MAC for your purpose, some samples that i could find that can point you in the right direction are mentioned in the link below

javascript - Is it possible to execute JSX scripts from outside ExtendScript? - Stack Overflow

Let us know how it goes.

-Manan


I did a quick test and it seemed to work, create a applescript file with the following text and save it. 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 jsx.

Hope this helps

-Manan

3 replies

Participant
December 31, 2019

When I tried this, I got an error message: 

"-bash: syntax error near unexpected token `do'"

Legend
December 31, 2019

These worked for me:

 

 

osascript -e 'tell application id "com.adobe.indesign" to do script "alert(\"a\")" language javascript'

osascript -e 'tell application id "com.adobe.indesign" to do script (posix file "/Users/dirk/test.jsx") language javascript'

 

 

InDesign is addressed using the version independent bundle ID of the application, also the file is specified as posix path as we're coming from terminal. An alias with a HFS path would also work as Manan wrote above.

 

When you copy-paste these lines, make sure that the single and double quotes are not "improved" by spell checkers.

Participant
January 3, 2020

Hi Dirk, any idea how to do the same with Photoshop? when I change com.adobe.indesign to photshop I'm receiving A “script” can’t go after this identifier.

BarlaeDC
Community Expert
Community Expert
February 10, 2019

Hi,

Ah, in that case the answer above is probably the only solution.

Regards

Malcolm

Trevor:
Legend
February 10, 2019

Not really adding much here but worth seeing Re: Call an ExtendScript Script from the Command Line

See Point 6 there.

From Windows one can use.

powershell -command "$ind = new-object -comobject InDesign.Application.CC.2018; $ind.DoScript('PathToFile', 1246973031)"

From Mac Terminal to run a script File (which can be more convenient) one can use

osascript  -e 'tell application "Adobe InDesign CC 2019" to do script alias "PathToFile" language javascript '''
BarlaeDC
Community Expert
Community Expert
February 7, 2019

Hi,

You can use the -cmd option with the ExtendScript toolkit to run a JSX file.

/Applications/Adobe ExtendScript Toolkit CC/ExtendScript Toolkit.app/Contents/MacOS/ExtendScript\ Toolkit -cmd /pathToJSXFile/file.jsx

The jsx file needs to have the target directive specified so it knows which application to use, and ExtendScript toolkit has to not be running.

Hope this helps.

Malcolm

Participant
February 8, 2019

Thanks for that Malcolm.

Extendscript Toolkit can be installed only on Mac OS 10.11.5 or earlier.

I am and our business currently using 10.13.6 or later.

Community Expert
February 8, 2019

Hi Ibrahim,

You might wanna investigate osascript on MAC for your purpose, some samples that i could find that can point you in the right direction are mentioned in the link below

javascript - Is it possible to execute JSX scripts from outside ExtendScript? - Stack Overflow

Let us know how it goes.

-Manan

-Manan