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

Run shell script from javascript

New Here ,
Jul 30, 2015 Jul 30, 2015

Hi all,

anybody know if it's possible to run a shell command from within javascript? The ultimate goal is to place a javascript in the Scripts Menu of Photoshop that would run an applescript. I know you're going to say why not just do the script in javascript but the script I'm trying to execute does a lot more outside of PhotoShop. As an applescript is not accessible from the Scripts Menu I wandered if I could get a javascript to execute the applescript. The reason that Shell script is mentioned in the subject is because I can execute an applescript using a simple shell command of : osacript /path/to/the/script/file.scpt So if JavaScript can run the shell command I should be able to get it to work.

Thanks for looking,

Nik

TOPICS
Actions and scripting
9.2K
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
Adobe
Community Expert ,
Jul 30, 2015 Jul 30, 2015

I moved you're post to Photoshop Scripting forum.

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
Advisor ,
Jul 30, 2015 Jul 30, 2015

app.system("osacript /path/to/the/script/file.scpt");

However, this is not a synchronous call. Depending on your apple script, it may continue to run after the function (app.system()) returns.

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 ,
Jul 30, 2015 Jul 30, 2015

Many thanks for the response.

I tried running this command from within ExtendScript:

app.system("osascript '/Applications/Adobe Photoshop CS5/Presets/Scripts/Save_and_Join_v1.scpt'");

but it just causes PhotoShop to hang.

If I run this command in Terminal it works fine:

osascript '/Applications/Adobe Photoshop CS5/Presets/Scripts/Save_and_Join_v1.scpt'

Any ideas why this would happen?

Thanks,

Nik

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
Advisor ,
Jul 30, 2015 Jul 30, 2015

Not sure why you are seeing the error. I suggest starting off with simpler .scpts and build up to see if that helps isolate the problem.

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 ,
Jul 30, 2015 Jul 30, 2015

My script is only saving the file to a new location. The only thing I can think that maybe causing the error is because my applescript displays a dialog before saving and this isn't appearing. I wander if the user interaction is a problem.

Thanks,

Nik

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
Advisor ,
Jul 30, 2015 Jul 30, 2015

I wander if the user interaction is a problem.

That would be a good guess. See if you can get around that AS dialog.

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 ,
Jul 31, 2015 Jul 31, 2015

I have managed to get my script to work. I had to save the applescript as an application then get the javascript to just open it like so:

app.system("open '/Applications/Adobe Photoshop CS5/Presets/Scripts/Save_and_Join_v1.app'")

Thanks for the help,

Nik

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
LEGEND ,
Jul 24, 2018 Jul 24, 2018

Shouldn't it be: app.system("osacript -e /path/to/the/script/file.scpt");

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 Beginner ,
May 13, 2020 May 13, 2020

I am seeing below error while ruuning this in Debugger

TypeError: app.system is not a function

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
LEGEND ,
May 13, 2020 May 13, 2020

Don't use app.system() in Debuger.

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 Beginner ,
May 13, 2020 May 13, 2020

I am trying to do the same , when i am trying to call app.system("open '/Applications/example.app'")

I see below error TypeError: app.system is not a function. I want to open application using shell command from 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
LEGEND ,
May 13, 2020 May 13, 2020

app.system() is extendscript specific command.

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 Beginner ,
May 14, 2020 May 14, 2020

Is there a way to call system calls from 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
LEGEND ,
May 14, 2020 May 14, 2020
system()
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 Beginner ,
May 15, 2020 May 15, 2020

ReferenceError: system is not defined 1:Console:Exec, no luck in 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
LEGEND ,
May 15, 2020 May 15, 2020

Did you put any content to system(), and ran .jsx with 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
Advisor ,
Jan 16, 2021 Jan 16, 2021

Do you happen to know the equivalent to this line on OSX.

app.system( 'osascript -e \'tell application "System Events" to key code "124"\'' ); 

 This line below tell the OS to press arrow key. Im looking for this for Windows however im really new to Windows so dont know shell or cmd i can use. 

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
LEGEND ,
Jan 16, 2021 Jan 16, 2021
LATEST

Do it with vbscript.

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