Copy link to clipboard
Copied
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 🙂
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("us
...
Copy link to clipboard
Copied
@Ghoul Fool have you thought of using AI to solve your scripting issue? CoPilot, Gemini, ChatGPT, etc
Copy link to clipboard
Copied
@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.
Copy link to clipboard
Copied
Using Ai for something very niche like Action Manager code - rarely results in anything working. It's a bit like following a wild goose to get specific directions.
Copy link to clipboard
Copied
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)?
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
I expect that would fall under currentToolOptions.
Copy link to clipboard
Copied
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);
Copy link to clipboard
Copied
You can use this to get a list of the properties.
The boolean »usePressureOverridesSize« seems to be the one you are interested in.
// 2025, use it at your own risk;
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID("capp"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
var applicationDesc = executeActionGet(ref);
checkDesc2 (applicationDesc.getObjectValue(stringIDToTypeID("currentToolOptions")), true);
////// based on code by michael l hale //////
function checkDesc2 (theDesc, theAlert) {
var c = theDesc.count;
var str = '';
for(var i=0;i<c;i++){ //enumerate descriptor's keys
str = str + 'Key '+i+' = '+typeIDToStringID(theDesc.getKey(i))+': '+theDesc.getType(theDesc.getKey(i))+'\n'+getValues (theDesc, i)+'\n';
};
if (theAlert == true) {alert("desc\n\n"+str);
return};
return str
};
////// check //////
function getValues (theDesc, theNumber) {
switch (theDesc.getType(theDesc.getKey(theNumber))) {
case DescValueType.ALIASTYPE:
return theDesc.getPath(theDesc.getKey(theNumber));
break;
case DescValueType.BOOLEANTYPE:
return theDesc.getBoolean(theDesc.getKey(theNumber));
break;
case DescValueType.CLASSTYPE:
return theDesc.getClass(theDesc.getKey(theNumber));
break;
case DescValueType.DOUBLETYPE:
return theDesc.getDouble(theDesc.getKey(theNumber));
break;
case DescValueType.ENUMERATEDTYPE:
return (typeIDToStringID(theDesc.getEnumerationValue(theDesc.getKey(theNumber)))+"_"+typeIDToStringID(theDesc.getEnumerationType(theDesc.getKey(theNumber))));
break;
case DescValueType.INTEGERTYPE:
return theDesc.getInteger(theDesc.getKey(theNumber));
break;
case DescValueType.LISTTYPE:
return theDesc.getList(theDesc.getKey(theNumber));
break;
case DescValueType.OBJECTTYPE:
return (theDesc.getObjectValue(theDesc.getKey(theNumber))+"_"+typeIDToStringID(theDesc.getObjectType(theDesc.getKey(theNumber))));
break;
case DescValueType.RAWTYPE:
return theDesc.getReference(theDesc.getData(theNumber));
break;
case DescValueType.REFERENCETYPE:
return theDesc.getReference(theDesc.getKey(theNumber));
break;
case DescValueType.STRINGTYPE:
return theDesc.getString(theDesc.getKey(theNumber));
break;
case DescValueType.UNITDOUBLE:
return (theDesc.getUnitDoubleValue(theDesc.getKey(theNumber))+"_"+typeIDToStringID(theDesc.getUnitDoubleType(theDesc.getKey(theNumber))));
break;
default:
break;
};
};
Copy link to clipboard
Copied
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 );
};
Copy link to clipboard
Copied
@Ghoul Fool , is the issue resolved?
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
It does here.
Did you use the last version of the code?
Otherwise please post screenshots to illustrate.
Copy link to clipboard
Copied
of course it doesn't work if the wacom tablets not plugged it!
So yes, it works with both brush, pencil and eraser tools. Thank you!