Skip to main content
Inspiring
April 4, 2024
Answered

Loop over available tools in Photoshop

  • April 4, 2024
  • 4 replies
  • 500 views

Is it possible to access app.tools as an array? I'm sure tools vary from PS version to version.

So loop over the array find their name and then access them by the name?

 

 

var str = "";
for (var i=0; i < tool.length; i++)
{
    str += i + " " + tool[i] + "\n";
}
alert(str);

 

 

0 moveTool
1 marqueeRectTool
2 marqueeEllipTool
3 marqueeSingleRowTool 

etc...

This topic has been closed for replies.
Correct answer c.pfaffenbichler

 

edited:

// based on code by michael l hale;
// 2024, use it at your own risk;
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID("capp"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") ); 
var applicationDesc = executeActionGet(ref);
var theToolsList = applicationDesc.getList(stringIDToTypeID("tools"));
var theList = new Array;
for (var m = 0; m < theToolsList.count; m++) {
	theList.push (theToolsList.getObjectValue(m).getString(stringIDToTypeID("toolID")))
	//checkDesc2 (theToolsList.getObjectValue(m))
};
alert (theToolsList.count+" tools:\n"+theList.join("\n"));
////////////////////////////////////
////// based on code by michael l hale //////
function checkDesc2 (theDesc) {
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';
	};
alert("desc\n\n"+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;
};
};

 

4 replies

c.pfaffenbichler
Community Expert
April 4, 2024

Filtering for »inToolBar« »true« I get 69 Tools. 

c.pfaffenbichler
Community Expert
April 4, 2024

What is the point here? 

Are you trying to determine the Photoshop version by the available Tools or what good is the list of Tools in your workflow? 

Inspiring
April 4, 2024

Everything is pointintless and nothing has meaning...

 

However, since in order to access each tool you need to know it's name.

It makes sense (to me at least) to get Photoshop to list them for you - just incase any commented list becomes outdated.

 

Does that make sense?

c.pfaffenbichler
Community Expert
April 4, 2024

Why do you want to »access each tool«? 

What is the actual point of the exercise? 

Stephen Marsh
Community Expert
April 4, 2024

I'm not aware of a property for app.tool or app.tools

 

There is app.currentTool

 

https://theiviaxx.github.io/photoshop-docs/Photoshop/Application/currentTool.html