Skip to main content
Inspiring
January 24, 2025
Answered

Get and set Photoshop Constant via Action Manager code

  • January 24, 2025
  • 3 replies
  • 729 views

Once again grasping straws in the Land of Sorrows™ of Action Manager script...

 

I'm trying to get and hopefully set a value from a Photoshop Constant "StlP" which *might* just be the pen pressure toggle.

 

So far, not so many straws:

 

var idselect = charIDToTypeID( "slct" );
var descriptor = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var reference = new ActionReference();
var id = charIDToTypeID( "StlP" ); // phKeyStylusIsPressure -> 1400138832 -> "StlP"  stylusIsPressure
reference.putClass( id );
descriptor.putReference( idnull, reference );
executeAction( idselect, descriptor, DialogModes.NO );

Obviously this script fails as clearly at this point I'm just typing random stuff in the vain hope it'll work 🙂

 

 

Correct answer c.pfaffenbichler

I've tried drilling down in teh AM code to get to currentToolOptions but it's an OBJECTTYPE  - which I don't know how to turn into an actionreference 

 

This is what I've got so far:

var str = "";
var topLevelObject = "application";
str += "Top Level Object: " + topLevelObject + "\n";
var r = new ActionReference ();
r.putEnumerated (stringIDToTypeID (topLevelObject), stringIDToTypeID ("ordinal"), stringIDToTypeID ("targetEnum"));
var d = executeActionGet (r);
var str = topLevelObject + " properties:\n";
var q = " - ";
for (var i = 0; i < d.count; i++) 
{ 
  str += typeIDToStringID(d.getKey(i)) + ':' + d.getType(d.getKey(i)) + "\n";
}


str += "\nDescriptor:\n";
var secondLayerObject = "currentToolOptions"; //Objecttpe
//currentToolOptions:DescValueType.OBJECTTYPE
str += secondLayerObject + "\n"

r = new ActionReference();
r.putEnumerated(stringIDToTypeID(secondLayerObject), stringIDToTypeID("object"), stringIDToTypeID("targetEnum"));

d = executeActionGet(r); // failes here

for (var i = 0; i < d.count; i++) 
{
  str += typeIDToStringID(d.getKey(i)) + q + d.getType(d.getKey(i)) + "\n";
}

alert(str);

 


Edited 2025-01-01

I included a check to enable/disable the setting depending on its current state. 

// enable or disable pressure for size depending on the current setting;
// 2025, use it at your own risk;
try {var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID("capp"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") ); 
var applicationDesc = executeActionGet(ref);
var enabled = applicationDesc.getObjectValue(stringIDToTypeID("currentToolOptions")).getBoolean(stringIDToTypeID("usePressureOverridesSize"));
if (enabled == false) {setCTO([["usePressureOverridesSize", true]], true)}
else {setCTO([["usePressureOverridesSize", false]], true)};
} catch (e) {};
/*
<javascriptresource>
<name>Switch Sample Mode</name>
<enableinfo>true</enableinfo>
<category>Hirlin Scripts</category>
</javascriptresource>
// Oleksii Hirlin 2021
*/
function getCTO(){
var ref = new ActionReference();
ref.putProperty(stringIDToTypeID("property"), stringIDToTypeID("currentToolOptions"));
ref.putEnumerated(stringIDToTypeID("application"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
return executeActionGet(ref).getObjectValue(stringIDToTypeID("currentToolOptions"));
};
// setting currentToolOptions with options array
function setCTO( options, isIdTypeString ){
var desc = new ActionDescriptor();
var ref = new ActionReference();
ref.putClass( stringIDToTypeID( app.currentTool ) );
desc.putReference( stringIDToTypeID( "target" ), ref );
// getting current tool options so that they do not get reset
var ctoObj = getCTO();
// check if we are setting the eyedropper tool
if ( app.currentTool=="eyedropperTool" ){
ctoObj.putInteger( stringIDToTypeID( options[0][0] ), options[0][1] );
} else {
// iteration through options array and putting booleans into cto descriptor
for (var i=0; i < options.length; i++){
if (isIdTypeString==true){
ctoObj.putBoolean( stringIDToTypeID( options[i][0] ), options[i][1] );
} else {
ctoObj.putBoolean( charIDToTypeID( options[i][0] ), options[i][1] );
}
}
}
desc.putObject( stringIDToTypeID( "to" ), stringIDToTypeID( "currentToolOptions" ), ctoObj );
executeAction( stringIDToTypeID( "set" ), desc, DialogModes.NO );
};

3 replies

c.pfaffenbichler
Community Expert
Community Expert
February 3, 2025

@Ghoul Fool , is the issue resolved? 

Inspiring
February 3, 2025

Sorry I've not had a chance to go over the script in detail. Obviously the script works but it doesn't seem to toggle the pen pressure on and off as expected - possibly because "StlP" might not be teh correct constant to shift.

c.pfaffenbichler
Community Expert
Community Expert
February 3, 2025

It does here. 

Did you use the last version of the code? 

 

Otherwise please post screenshots to illustrate. 

c.pfaffenbichler
Community Expert
Community Expert
January 31, 2025

What are you trying to do exactly? 

Change the Pressure setting for a painterly Tool? If so which Pressure setting (as Pressure can aply to many different aspects)? 

Inspiring
January 31, 2025

I want to know if the pressure sensiticity button can be swtiched off via code. 

Initally I thought it could be toggle with a keyboardshortcut - no such luck. 

Scriptlistner doesn't come up with anything when it's toggled.  - no good there.

I did look up "StlP" as one of the four letter codes Photoshop uses. At which point I find myself trying to shoe-horn a Photoshop constant into Action Manager code which is the equivalent of  giving a cat a spanner and telling it to fix a vaccuum cleaner.

 

c.pfaffenbichler
Community Expert
Community Expert
January 31, 2025

I expect that would fall under currentToolOptions. 

creative explorer
Community Expert
Community Expert
January 31, 2025

@Ghoul Fool have you thought of using AI to solve your scripting issue? CoPilot, Gemini, ChatGPT, etc

m
c.pfaffenbichler
Community Expert
Community Expert
January 31, 2025
quote

@Ghoul Fool have you thought of using AI to solve your scripting issue? CoPilot, Gemini, ChatGPT, etc

Judging from posts on this Forum using generative AI for Photoshop Scripting often (or at least sometimes) results in nonsensical code.

I assume the volume of training material is limited and the Scripting for different Adobe applications (Indesign, Illustrator, Photoshop, …) is similar enough that those text generators sometimes mix them together.