Run shell script from javascript
Copy link to clipboard
Copied
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
Explore related tutorials & articles
Copy link to clipboard
Copied
I moved you're post to Photoshop Scripting forum.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
I wander if the user interaction is a problem.
That would be a good guess. See if you can get around that AS dialog.
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
Shouldn't it be: app.system("osacript -e /path/to/the/script/file.scpt");
Copy link to clipboard
Copied
I am seeing below error while ruuning this in Debugger
TypeError: app.system is not a function
Copy link to clipboard
Copied
Don't use app.system() in Debuger.
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
app.system() is extendscript specific command.
Copy link to clipboard
Copied
Is there a way to call system calls from javascript?
Copy link to clipboard
Copied
system()
Copy link to clipboard
Copied
ReferenceError: system is not defined 1:Console:Exec, no luck in javascript
Copy link to clipboard
Copied
Did you put any content to system(), and ran .jsx with Photoshop?
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Do it with vbscript.

