• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
3

script to get Photoshop Swatch Group or ACT file color values into javascript array

Explorer ,
May 20, 2024 May 20, 2024

Copy link to clipboard

Copied

I’d like to get the color values from a Photoshop Swatch Group or from an ACT color table file into an array for processing in javascript.

 

Examples from this post can either add a new Swatch Group or get the names of the colors in Preset Swatch Groups.

https://community.adobe.com/t5/photoshop-ecosystem-discussions/scripting-how-to-get-swatch-group-nam...

 

And this script will import a new Swatch Group from an ACT file:

var idsetd = charIDToTypeID( "setd" );
var desc318 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref4 = new ActionReference();
var idPrpr = charIDToTypeID( "Prpr" );
var idClrs = charIDToTypeID( "Clrs" );
ref4.putProperty( idPrpr, idClrs );
var idcapp = charIDToTypeID( "capp" );
var idOrdn = charIDToTypeID( "Ordn" );
var idTrgt = charIDToTypeID( "Trgt" );
ref4.putEnumerated( idcapp, idOrdn, idTrgt );
desc318.putReference( idnull, ref4 );
var idT = charIDToTypeID( "T " );
desc318.putPath( idT, new File( "C:\\Users\\[userName]\\Pictures\\color tables\\test color table.act" ) );
var idAppe = charIDToTypeID( "Appe" );
desc318.putBoolean( idAppe, true );
executeAction( idsetd, desc318, DialogModes.NO );


This code lists Swatch Groups with their member Color Names, but the 'presetManager' appears to not include any of the imported Swatch Groups.

 

I’m also not sure how to get from the Color Name to color values that can be used in a Fill:

var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID("capp"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
var desc = executeActionGet(ref);// get the app descriptor
var presetsList = desc.getList(stringIDToTypeID('presetManager'));// the presets list
var swatchDesc = presetsList.getObjectValue(1);// swatches is the second key
var nameList = swatchDesc.getList(charIDToTypeID("Nm  "));// there is only one key in the swatch descriptor so get the list
var nameOfFirstSwatch = nameList.getString(0);// all the name list keys are strings data types so get the first swatch name

var nList = new Array();
for (var i=0;i<nameList.count;i++){
 if (nameList.getString(i).slice(0,1)=="P")   {
nList.push(nameList.getString(i)+"\n")
}
}
alert(nList)


And this script will create a new empty swatch group with name “My Test”:

var idmake = stringIDToTypeID( "make" );
    var desc1530 = new ActionDescriptor();
    var idnull = stringIDToTypeID( "null" );
        var ref549 = new ActionReference();
        var idswatchFolderClass = stringIDToTypeID( "swatchFolderClass" );
        ref549.putClass( idswatchFolderClass );
    desc1530.putReference( idnull, ref549 );
    var idname = stringIDToTypeID( "name" );
    desc1530.putString( idname, """myTest""" );
executeAction( idmake, desc1530, DialogModes.NO );

 

How can I get the color values from an imported member of the swatchFolderClass into a javascript array?

 

Or, can I get these color values directly from an ACT file into a javascript array?

 

Thanks!

TOPICS
Actions and scripting , Windows

Views

72

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe
Community Expert ,
May 21, 2024 May 21, 2024

Copy link to clipboard

Copied

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 21, 2024 May 21, 2024

Copy link to clipboard

Copied

Thanks.  I might be able to get this script to work if I can find another script that will convert ACT files to ACO files.  My process begins with creating two or more ACT files.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 21, 2024 May 21, 2024

Copy link to clipboard

Copied

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 21, 2024 May 21, 2024

Copy link to clipboard

Copied

LATEST

I think xbytor and peter gun have posted code on act-files that I utilized (without much comprehension) but it seems I cannot locate their original posts at current. 

https://community.adobe.com/t5/photoshop-beta-discussions/printing-color-numbers-in-photoshop/m-p/14...

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines