Highlighted

Passing Arguments From Extendscript to AppleScript

Explorer ,
Feb 21, 2020

Copy link to clipboard

Copied

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!

Adobe Community Professional
Correct answer by r-bin | Adobe Community Professional

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.

 

Topics

Actions and scripting, SDK

Views

805

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Passing Arguments From Extendscript to AppleScript

Explorer ,
Feb 21, 2020

Copy link to clipboard

Copied

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!

Adobe Community Professional
Correct answer by r-bin | Adobe Community Professional

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.

 

Topics

Actions and scripting, SDK

Views

806

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Adobe Community Professional ,
Feb 22, 2020

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Explorer ,
Feb 22, 2020

Copy link to clipboard

Copied

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).

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Most Valuable Participant ,
Feb 22, 2020

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Explorer ,
Feb 22, 2020

Copy link to clipboard

Copied

Thanks for the reply. For clarification, I'm using AppleScript as part of a larger process to communicate with other programs (specificially Acrobat). All my interaction with Photoshop itself is done in JavaScript.

 

I'm able to pass parameters to AppleScript with app.doScript in InDesign but unfortunately it doesn't work in Photoshop.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Most Valuable Participant ,
Feb 22, 2020

Copy link to clipboard

Copied

I do not see many users that use AppleScript participate here mostly seen JavaScript here there  are some JavaScripts scripts posted here that use  Adobe Scripts  as part of their processing like adobe merge to HDR and some Adobe scripts use scripts in the stack scripts only folder they may or may be passes arguments. None are AppleScripts thes scrripts are user on bothe PC and Mac.  

 

There is some AppleScript code posted in the forum. However, There is a big problem here this site search is unuseable if may find what you want but you can only view a few of the thing search finds. So if you want to seacrch for AppleScript code here use Google search.

JJMack

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Adobe Community Professional ,
Feb 22, 2020

Copy link to clipboard

Copied

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.

 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Explorer ,
Feb 23, 2020

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Community Beginner ,
Sep 04, 2020

Copy link to clipboard

Copied

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!

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Explorer ,
Sep 04, 2020

Copy link to clipboard

Copied

Hi Sean,

 

You'd first set your custom option in ExtendScript, then execute your AppleScript.

var desc = new ActionDescriptor();
desc.putString(0, 'Sample text string');
app.putCustomOptions('testMessage', desc, false);

var appleScriptFile = new File('~/Desktop/example.app');
appleScriptFile.execute();

 

In your AppleScript file, you can access your custom options via do javascript. In this example, retrievedStr would be set to "Sample test string."

tell application id "com.adobe.Photoshop"
  set retrievedStr to do javascript "(function() {return app.getCustomOptions('testMessage').getString(0)})()"
end tell

 

Hopefully this helps!

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Community Beginner ,
Sep 08, 2020

Copy link to clipboard

Copied

Thanks so much!  We got it working on our end.  REALLY useful!

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...