Skip to main content
leo.r
Community Expert
Community Expert
sept. 27, 2019 8:18 PM UTC
Répondu

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

The "resize image" command in AppleScript performs the Image Size command in Photoshop.

However, with the AppleScript's command, the Scale Styles option is not enabled. Which, obviously, leads to undesired results in many cases.

Unless I'm missing something, there's no way to enable the Scale Styles option in AppleScript.

So I hope Adobe can add this parameter to the "resize image" command in AppleScript.


Thanks,
Leo

Ce sujet a été fermé aux réponses.
Chuck Uebele
Chuck UebeleRéponse
Community Expert
sept. 27, 2019 10:56 PM UTC

Unfortunately, I don't know AppleScript, nor do I have a Mac. However, with Javascript and scriptListener, you can record to scale layer styles. Does AppleScript work with scriptListener? Here is the javascript code that shows the scale styles:

var idImgS = charIDToTypeID( "ImgS" );
    var desc764 = new ActionDescriptor();
    var idWdth = charIDToTypeID( "Wdth" );
    var idPrc = charIDToTypeID( "#Prc" );
    desc764.putUnitDouble( idWdth, idPrc, 50.000000 );
    var idscaleStyles = stringIDToTypeID( "scaleStyles" );
    desc764.putBoolean( idscaleStyles, true );//scale styles here
    var idCnsP = charIDToTypeID( "CnsP" );
    desc764.putBoolean( idCnsP, true );
    var idIntr = charIDToTypeID( "Intr" );
    var idIntp = charIDToTypeID( "Intp" );
    var idbicubicSharper = stringIDToTypeID( "bicubicSharper" );
    desc764.putEnumerated( idIntr, idIntp, idbicubicSharper );
executeAction( idImgS, desc764, DialogModes.NO );

13 commentaires

Stephen Marsh
Community Expert
Community Expert
janv. 31, 2020 1:15 PM UTC

UPDATE: After some searching, I managed to get an externally referenced .jsx to run when called from an AppleScript!

 

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

 

Or slightly different syntax to call the external script, here I have used different path delimiters, both types are valid and this makes no difference to the call:

 

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

 

Traduire
Participant
mai 20, 2023 11:39 AM UTC

Adding to this:

I found that the following would work for passing in arguments

 
JavaScript

 

function testFunc(t) {
 alert('argument one: ' + t[0] + '\r' + 'argument two: ' + t[1]);
}

testFunc(arguments);

 

 
AppleScript

 

tell application id "com.adobe.Photoshop"
activate
do javascript of file "pathToFile" with arguments {"foo", "bar"}
end tell

 

Traduire
Stephen Marsh
Community Expert
Community Expert
sept. 28, 2019 3:32 AM UTC

OK, minor progress...

 

I can't get a reference to an external js/jsx file to work.

 

I can get a simple single inline line of code to run:

 

 

tell application "Adobe Photoshop CC 2019"
	activate
	do javascript "alert('Hello Photoshop!');"
end tell

 

 

or something a little bit more exciting (select all layers menu command):

 

 

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

 

 

However my attempts at getting multi-line Script Listener recorded AM code to work have failed with AS compiler errors.

 

 

Traduire
leo.r
Community Expert
leo.rCommunity ExpertAuteur
Community Expert
sept. 28, 2019 3:37 AM UTC
you need to escape all quotes in the script. as to path to external file then i couldn't make it work either. tell application "Adobe Photoshop CC 2019" set js to "var idImgS = charIDToTypeID( \"ImgS\" ); var desc764 = new ActionDescriptor(); var idWdth = charIDToTypeID( \"Wdth\" ); var idPrc = charIDToTypeID( \"#Prc\" ); desc764.putUnitDouble( idWdth, idPrc, 50.000000 ); var idscaleStyles = stringIDToTypeID( \"scaleStyles\" ); desc764.putBoolean( idscaleStyles, true );//scale styles here var idCnsP = charIDToTypeID( \"CnsP\" ); desc764.putBoolean( idCnsP, true ); var idIntr = charIDToTypeID( \"Intr\" ); var idIntp = charIDToTypeID( \"Intp\" ); var idbicubicSharper = stringIDToTypeID( \"bicubicSharper\" ); desc764.putEnumerated( idIntr, idIntp, idbicubicSharper ); executeAction( idImgS, desc764, DialogModes.NO );" --do javascript js end tell
Traduire
leo.r
Community Expert
leo.rCommunity ExpertAuteur
Community Expert
sept. 28, 2019 3:38 AM UTC
umm i don't know what's up with the Reply function on this forum... I'll try to repost.
Traduire
Stephen Marsh
Community Expert
Community Expert
sept. 28, 2019 2:38 AM UTC

It is the same for JavaScript, this option is not available using the standard reference code.

 

Untested Idea: As AppleScript can call JS code, you would need to incorporate the desired chunk of JS code into your AS code. You can put the script "inline" or reference an external JS file.

Traduire
leo.r
Community Expert
leo.rCommunity ExpertAuteur
Community Expert
sept. 28, 2019 2:56 AM UTC
Thanks - yes I tried it and I can run it from AppleScript
Traduire
Stephen Marsh
Community Expert
Community Expert
sept. 28, 2019 3:33 AM UTC
Can you please share your working AS/JS code? As you will see from below, I have been trying to work this out for you, with only limited success...
Traduire
Chuck Uebele
Community Expert
Chuck UebeleCommunity ExpertRéponse
Community Expert
sept. 27, 2019 10:56 PM UTC

Unfortunately, I don't know AppleScript, nor do I have a Mac. However, with Javascript and scriptListener, you can record to scale layer styles. Does AppleScript work with scriptListener? Here is the javascript code that shows the scale styles:

var idImgS = charIDToTypeID( "ImgS" );
    var desc764 = new ActionDescriptor();
    var idWdth = charIDToTypeID( "Wdth" );
    var idPrc = charIDToTypeID( "#Prc" );
    desc764.putUnitDouble( idWdth, idPrc, 50.000000 );
    var idscaleStyles = stringIDToTypeID( "scaleStyles" );
    desc764.putBoolean( idscaleStyles, true );//scale styles here
    var idCnsP = charIDToTypeID( "CnsP" );
    desc764.putBoolean( idCnsP, true );
    var idIntr = charIDToTypeID( "Intr" );
    var idIntp = charIDToTypeID( "Intp" );
    var idbicubicSharper = stringIDToTypeID( "bicubicSharper" );
    desc764.putEnumerated( idIntr, idIntp, idbicubicSharper );
executeAction( idImgS, desc764, DialogModes.NO );
Traduire
leo.r
Community Expert
leo.rCommunity ExpertAuteur
Community Expert
sept. 28, 2019 2:51 AM UTC

Thanks Chuck,

 

I can run it from AppleScript and it works!

Better than nothing - but I hope that Adobe will listen and give us the Scale Styles option as a regular AppleScript parameter.

Traduire