Skip to main content
Known Participant
April 8, 2020
Answered

Running a jsx script with AppleScript in Photoshop using do javascript

  • April 8, 2020
  • 1 reply
  • 4928 views

Hi everybody! I just wrote a script in javascript for Photoshop and it works perfectly. I just wanted to implement an action in automator that opens Photoshop and runs this script. I tried to run an Applescript but I spent hours with the function "do javascript..." following the reference on javascript for Photoshop without success. I dont know if its a problem of syntax or its not the good function. I precise that this only line worked :

do javascript "alert(1)". And it showed 1, but no way to run my script. Even "do javascript "alert("Hello World") " doesnt work. Any help is welcome ! 

ps: Im a beginner!

This topic has been closed for replies.
Correct answer Stephen Marsh

One method to point to an external JSX file:

 

 

tell application "Adobe Photoshop CC 2019"
	activate
	do javascript of file "/Users/username/Desktop/alert.jsx"
end tell

 

 

Or slightly different syntax:

 

 

tell application "Adobe Photoshop CC 2019"
	activate
	do javascript (file "Users:username:Desktop:alert.jsx")
end tell

 

 

To run the JS code inline within the AppleScript:

 

 

tell application "Adobe Photoshop CC 2019"
	activate
	do javascript "app.runMenuItem(stringIDToTypeID('selectAllLayers'));"
end tell

 

 

And if there are double quotes in the code, they need to be escaped as shown here:

 

\"

 

http://community.adobe.com/t5/Photoshop/Request-Add-Scale-Styles-option-to-quot-resize-image-quot/m-p/10637321

 

Good luck Tonio1812 and please let the forum know how it worked out for you!

1 reply

Stephen Marsh
Community Expert
Stephen MarshCommunity ExpertCorrect answer
Community Expert
April 8, 2020

One method to point to an external JSX file:

 

 

tell application "Adobe Photoshop CC 2019"
	activate
	do javascript of file "/Users/username/Desktop/alert.jsx"
end tell

 

 

Or slightly different syntax:

 

 

tell application "Adobe Photoshop CC 2019"
	activate
	do javascript (file "Users:username:Desktop:alert.jsx")
end tell

 

 

To run the JS code inline within the AppleScript:

 

 

tell application "Adobe Photoshop CC 2019"
	activate
	do javascript "app.runMenuItem(stringIDToTypeID('selectAllLayers'));"
end tell

 

 

And if there are double quotes in the code, they need to be escaped as shown here:

 

\"

 

http://community.adobe.com/t5/Photoshop/Request-Add-Scale-Styles-option-to-quot-resize-image-quot/m-p/10637321

 

Good luck Tonio1812 and please let the forum know how it worked out for you!

Participant
February 22, 2021

I know it's been a year since this was posted but I just spent an hour trying to find an answer about how to run jsx scripts for photoshop from command line and this is the first answer I've found that worked, so I just wanted to say thank you so much for sharing this!

Stephen Marsh
Community Expert
Community Expert
February 22, 2021

It took me a lot of time and effort to track down code that worked, it appears that there is a lot of older code on various web pages and forums that no longer works with newer versions of Photohsop. Glad it helped you!