Skip to main content
shelbycott
Known Participant
February 22, 2020
Answered

Passing Arguments From Extendscript to AppleScript

  • February 22, 2020
  • 2 replies
  • 3451 views

Hi everyone,

 

Not too optimistic about this one, but does anyone know if there's a way to pass arguments from Extendscript to AppleScript in Photoshop? I've been searching forever but the only method I've found for executing AppleScript from JSX in Photoshop is the following:

 

var appleScriptFile = new File("~/Desktop/AppleScript.app");
appleScriptFile.execute();

 

Any ideas or workarounds are greatly appreciated. Thanks so much!

This topic has been closed for replies.
Correct answer r-bin

You can try to use (see docs)

app.putCustomOptions

app.getCustomOptions

app.eraseCustomOptions

to set some parameters before call apple_script.

In apple_script you can try get this parameters.

 

2 replies

r-binCorrect answer
Legend
February 22, 2020

You can try to use (see docs)

app.putCustomOptions

app.getCustomOptions

app.eraseCustomOptions

to set some parameters before call apple_script.

In apple_script you can try get this parameters.

 

shelbycott
Known Participant
February 23, 2020

Wonderful, this is exactly what I needed. Thank you so much—appreciate the help!

Participant
September 4, 2020

Mind sharing some more info about your solution?  I'm very familiar with AppleScript but not ExtendScript and need to execute this exact thing.  Just not sure how the AppleScript receives the parameters set by the ExtendScript.

Thanks!

Kukurykus
Legend
February 22, 2020

I think there you can find (also browsing available links) how to do that from AS to ES:

Execute JavaScript in Photoshop CC 2019 via Applescript

shelbycott
Known Participant
February 22, 2020

Hi, thanks for the reply! I know how to run JavaScript from AppleScript, but I'm trying to do the reverse (calling AppleScript from a Photoshop panel JSX file).

JJMack
Community Expert
Community Expert
February 22, 2020

Most user are Windows users and Most Mac photoshop User that script Photoshop use  JavaScript because it works cross platforms.  I have never even look at AppleScript documentation.  I have seen Photoshop JavaScripts like Image Processor.jsx that pass arguments to the Photoshop Plug-in Fit Image which also happens to be implemented in JavaScript since CS2 or CS3.   To be able to pass arguments to something the something must be coded to process arguments that are pass someway.   How does the external AppleScript get executed and how is it coded to process arguments that may be passed to it.  

 

Fit Image is a Photoshop Script that happens to be a Photoshop Plug-in.  If it is not passed argument settings it will display a dialog and get the Arguments from user interaction in its dialog.  And If its is being recorded into an Action step the script will record the arguments the user set into the Action Step.  When that Actions is Played the Action Manager will Pass the recorded argument in the action step to the plug-in script.  The script will bypass displaying its dialog and use the passed arguments.

 

How does your AppleScript Process Arguments and how should the argements be passed.

 

Here is how Image Processor passes arguments to Fit Image

 

 

FitImage( this.params["tiffw"], this.params["tiffh"] ); 

// 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 );
}

 

 

Note: The Plug-in is run by the Action manager code the That Passes arguments to the Plug-in using the Plug-in UUID.

 

It is not done by throwing the plug-in file over the wall to the OS file system file association like this

var appleScriptFile = new File("~/Desktop/AppleScript.app");
appleScriptFile.execute();

 

JJMack