Skip to main content
Inspiring
January 24, 2020
Question

Execute JavaScript in Photoshop CC 2019 via Applescript

  • January 24, 2020
  • 5 replies
  • 2183 views

Hello,

I am new to applescript and was wondering if there is a way to execute the Image Processor javascript via applescript.Image Processor is a javascript where you need to press the Run button in order to execute it. The current code I have doesn't do the trick:

 

tell application "Adobe Photoshop CC 2019"
	activate
	do javascript (file "Macintosh HD:Applications:Adobe Photoshop CC 2019:Presets:Scripts:Image Processor.jsx")
	
	delay 10
	tell application "System Events" to click at {1550, 450}
end tell

 

I had a look at the following post but it didn't fully answer my question.

 

 

This topic has been closed for replies.

5 replies

Legend
January 25, 2020
I can not and do not use applescript.

But
 
1. Try to assign a hotkey to the script and send this keyboard shortcut to Photoshop instead of "do javascript".

2. Try to call the script through the menu.

Not sure if anything will work out.

I found information on how to do it here What is "System Events"?
 
JJMack
Community Expert
Community Expert
January 25, 2020

The Image Processor Script is not a Photoshop Plug-in. The Image Proessor's interactive Dialog can not be bypassed like Plug-in dialogs can be by Action step using the plug-in or the script using the plug-in which pass the settings for the Plug-in dialog recorder into the Action step by the plug-in when the Actions was recorder, or the Script passing the Plug-in the settings for its dialog. The plug-in will bypass displaying its Dialog when the setting are pass.    I do not know anything about Apple or what your code after calling Image processor is for

"

 

	delay 10
	tell application "System Events" to click at {1550, 450}

 

"

That code would not execute till after the image processor script finish running. I hope that System event  click at 1550, 450 is not intended to click on the Image processor dialog run button.

 

The Image Processor Pro... is a Photoshop Plug-in script its dialog can be bypassed when you call it you can pass  the dialog settings you want it to use.  It has a quite complex dialog.  It may be easier to record using the Image Processor Pro in an actions and let Image Processor Pro... record the settings you use in its dialog recording the action step. Then have your applet script run your action that has the step menu File>Automate>Image Processor Pro... .

 

The Image Processor... script uses Adope Plug-in Fit Image which is a Plug-in script here is the code from Image Processor script to call Fit Omage and bypass the Fit Image dialog. It uses action manager code

 

// use the fit image automation plug-in to do this work for me
function FitImage( inWidth, inHeight ) {
	if ( inWidth == undefined || inHeight == undefined ) {
		alert( strWidthAndHeight );
		return;
	}
	var desc = new ActionDescriptor();
	var unitPixels = charIDToTypeID( '#Pxl' );
	desc.putUnitDouble( charIDToTypeID( 'Wdth' ), unitPixels, inWidth );
	desc.putUnitDouble( charIDToTypeID( 'Hght' ), unitPixels, inHeight );
	var runtimeEventID = stringIDToTypeID( "3caa3434-cb67-11d1-bc43-0060b0a13dc4" );	
	executeAction( runtimeEventID, desc, DialogModes.NO );
}

 

JJMack
Inspiring
January 25, 2020

Unfortunately the do Javascript code keeps executing until you press the return or esc key on the keyboard.

Only then will the do Javascript code finish and the line for the system events execute.

Stephen Marsh
Community Expert
Community Expert
January 24, 2020

Try here, inline code works fine, but an external reference does not:

 

Request: Add Scale Styles option to "resize image" command in AppleScript

Kukurykus
Legend
January 24, 2020

If I'm right 'do javascript' is not Photoshop, but Illustrator specific.

osterburgAuthor
Inspiring
January 24, 2020

This is from the scripting guide on page 80.

 

 

 

Kukurykus
Legend
September 5, 2020

That's right, I forgot it's special command for Apple Script.