Skip to main content
Participating Frequently
August 19, 2025
Question

Scripting a Photoshop Action: Convert Image to Indexed Color (Perceptual) and Save Color Table

  • August 19, 2025
  • 2 replies
  • 193 views

Hi everyone,

I'm trying to create a Photoshop script that performs two main tasks, regardless of the initial color mode of the open image (e.g., RGB, CMYK, Grayscale).

1. Convert the image to Indexed Color. The specific settings I need are:

- Palette: Perceptual (Local Adaptive)

- Colors: 128

2. Save the resulting color table (also known as the color palette) to a specific destination folder.

I've been looking through the Photoshop scripting API but am having trouble finding the exact commands or syntax to achieve this, especially for the "Local Adaptive" option and saving the color table.

Could someone please provide a code snippet or point me in the right direction? I'm primarily working with JavaScript (JSX) for this.

Any help would be greatly appreciated!

Thanks

2 replies

Stephen Marsh
Community Expert
Community Expert
August 19, 2025

I am not aware of DOM or AM code to save an .act file via scripting. Perhaps someone else can comment.

Stephen Marsh
Community Expert
Community Expert
August 19, 2025

 

Where the DOM is lacking, there is AM (Action Manager) code:

var idCnvM = charIDToTypeID( "CnvM" );
    var desc5609 = new ActionDescriptor();
    var idT = charIDToTypeID( "T   " );
        var desc5610 = new ActionDescriptor();
        var idPlt = charIDToTypeID( "Plt " );
        var idClrP = charIDToTypeID( "ClrP" );
        var idAdpt = charIDToTypeID( "Adpt" );
        desc5610.putEnumerated( idPlt, idClrP, idAdpt );
        var idClrs = charIDToTypeID( "Clrs" );
        desc5610.putInteger( idClrs, 128 );
        var idFrcC = charIDToTypeID( "FrcC" );
        var idFrcC = charIDToTypeID( "FrcC" );
        var idBanW = charIDToTypeID( "BanW" );
        desc5610.putEnumerated( idFrcC, idFrcC, idBanW );
        var idTrns = charIDToTypeID( "Trns" );
        desc5610.putBoolean( idTrns, true );
        var idDthr = charIDToTypeID( "Dthr" );
        var idDthr = charIDToTypeID( "Dthr" );
        var idDfsn = charIDToTypeID( "Dfsn" );
        desc5610.putEnumerated( idDthr, idDthr, idDfsn );
        var idDthA = charIDToTypeID( "DthA" );
        desc5610.putInteger( idDthA, 75 );
    var idIndC = charIDToTypeID( "IndC" );
    desc5609.putObject( idT, idIndC, desc5610 );
executeAction( idCnvM, desc5609, DialogModes.NO );

 

Or put through the CleanSL script:

var c2t = function (s) {
	return app.charIDToTypeID(s);
};
var s2t = function (s) {
	return app.stringIDToTypeID(s);
};
var descriptor = new ActionDescriptor();
var descriptor2 = new ActionDescriptor();
descriptor2.putEnumerated( s2t( "palette" ), c2t( "ClrP" ), s2t( "adaptive" ));
descriptor2.putInteger( s2t( "colors" ), 128 );
descriptor2.putEnumerated( s2t( "forcedColors" ), s2t( "forcedColors" ), s2t( "blackAndWhite" ));
descriptor2.putBoolean( c2t( "Trns" ), true );
descriptor2.putEnumerated( s2t( "dither" ), s2t( "dither" ), s2t( "diffusion" ));
descriptor2.putInteger( s2t( "ditherAmount" ), 75 );
descriptor.putObject( s2t( "to" ), s2t( "indexedColorMode" ), descriptor2 );
executeAction( s2t( "convertMode" ), descriptor, DialogModes.NO );

 

In this case, the code was recorded via the ScriptingListener plug-in:

 

https://helpx.adobe.com/photoshop/kb/downloadable-plugins-and-content.html