Skip to main content
Inspiring
April 20, 2019
Question

Get List Of All Swatch Values

  • April 20, 2019
  • 2 replies
  • 1053 views

Hello to all

I came across some code by Mike Hale which gets a list of all swatch names currently loaded into the swatches panel.

I added a few other sections to the script to save these names to a text file.

So this script generates a list of swatch names of all the swatches currently loaded into the swatches panel, and then saves it as a .txt file to your c: drive.

Here is my queston:

Instead of swatch names, how can we get a list of the swatch values instead?

For example a list such as:

cbddac

ff6d25

7c6000

...of all the swacthes currently in the panel.

Can this be done?

Here is the code:

// based on mike hale’s code;

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 theNames = new Array;

for (var m = 0; m < nameList.count; m++) {

theNames.push(nameList.getString(m))

};

logInfo(theNames.join("\n"));

function logInfo(Txt){   

var file = new File("/c/SWATCH_CODES.txt"); 

file.remove("/c/SWATCH_CODES.txt"); 

file.open("e", "TEXT", "????");   

file.seek(0,2);   

$.os.search(/windows/i)  != -1 ? file.lineFeed = 'windows'  : file.lineFeed = 'macintosh';   

file.writeln(Txt);   

file.close();   

}; 

This topic has been closed for replies.

2 replies

Legend
April 22, 2019

Look at here.Re: Find and replace colors from .aso palettes

Pay attention to the function get_color(i).

gangeekAuthor
Inspiring
April 24, 2019

Hi r-bin, I tried running the code, but am getting this error:

the line "set" is not currently available

line: 94

gangeekAuthor
Inspiring
April 21, 2019

After some more experimentation, I've discovered that if the existing swatches in the panel were loaded from an .ACT file instead of an .ACO file, then each swatch is named by its HEX value. For example,

#cda855

#411a1a

#0005cb

...etc.

But to create an .ACT file, first you need to load an image into Photoshop, then convert it to Index Mode and reduce the amount of colors to something like 256 (or any number of your choice), then go into "Image/Mode/Color Table..." and save the new set of swatches which appear in the grid as an as .ACT file (not an .ACO file - you need to change this in the drop-down menu when saving as)

THEN, you need to go into the swatches panel and select "Load Swatches..." and then change the drop-down menu again to ".ACT" and then select the .ACT file we just saved. Only now do we have an .ACT file loaded into the swatches panel, and each swatch name is now named after each swatch color's HEX code.

Phew! Is there a faster way to do this? Just automatically export all HEX codes of each swatch to a text file other than having to go through this long process?