Get List Of All Swatch Values
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();
};
