Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Run 2019 jsx scripts from mac terminal

New Here ,
Feb 05, 2019 Feb 05, 2019

Is it still possible to run javascripts from mac terminal?

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

TOPICS
Scripting
6.1K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Feb 07, 2019 Feb 07, 2019

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

Translate
Community Expert ,
Feb 07, 2019 Feb 07, 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 07, 2019 Feb 07, 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 07, 2019 Feb 07, 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 07, 2019 Feb 07, 2019

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 10, 2019 Feb 10, 2019

Thanks Manan

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 10, 2019 Feb 10, 2019

Hi,

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

Regards

Malcolm

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Feb 10, 2019 Feb 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 '''
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 31, 2019 Dec 31, 2019

When I tried this, I got an error message: 

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Dec 31, 2019 Dec 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 03, 2020 Jan 03, 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Jan 04, 2020 Jan 04, 2020

Working from AppleScript Editor:

get id of application "arbitrary name"

Assuming you misspelled that arbitrary name, the AS editor will display a dialog "Choose Application" with all available applications. From there choose Photoshop, and the result area of the AS editor will display the string

"com.adobe.Photoshop"

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 04, 2020 Jan 04, 2020
LATEST

The original post is a year old, and I don’t think it was clear why Terminal is needed, but if you simply want to run the JS outside of Photoshop, an AppleScript could be saved as an Application, droplet, or saved to Library>Scripts folder and run from the Finder Script menu. This has the JS code in the script and creates a new PS document, but you could also reference an external JS:

 

Screen Shot 2.png

 

 

 

tell application id "com.adobe.photoshop"
	--do javascript alias "Users:username:Desktop:NewDocument.jsx"
	do javascript "app.preferences.rulerUnits = Units.INCHES;
					var newDocumentRef = app.documents.add(4, 4, 72.0, 'My New Document');"
end tell

 

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines