I think this should get you close… There are other ways too…
Contains NO error trapping… Files are saved in folder Swatches on your desktop…
#target photoshop
selectCSV();
function selectCSV() { if ( /Macintosh/i.test( $.os ) ) { var csvFile = File.openDialog( 'Select a CSV File', function (f) {return ( f instanceof Folder ) || f.name.match( /\.csv$/i );} ); }else{ var csvFile = File.openDialog( 'Select a CSV File', 'comma-separated-values(*.csv):*.csv;' ); }; if ( csvFile != null ) { var fileArray = readInCSV( csvFile ) }; var swatches = Folder( Folder.desktop + '/Swatches' ); if ( ! swatches.exists ) { swatches.create(); } createSwatches( fileArray, swatches )};
function createSwatches( fileArray, saveFolder ) { var userUnits = app.preferences.rulerUnits; app.preferences.rulerUnits = Units.PIXELS; var doc = app.documents.add( 100, 100, 72, 'fluff', NewDocumentMode.LAB, DocumentFill.TRANSPARENT ); var opts = new TiffSaveOptions(); opts.byteOrder = ByteOrder.MACOS; opts.imageCompression = TIFFEncoding.TIFFLZW; opts.layers = false; doc.selection.selectAll(); for ( var i = 0; i < fileArray.length; i++ ) { var n = fileArray[i][0]; var l = parseInt( fileArray[i][1] ); var a = parseInt( fileArray[i][2] ); var b = parseInt( fileArray[i][3] ); if ( l >= 0 && l <= 100 && a >= -128 && a <= 127 && b >= -128 && b <= 127 ) { var lab = new LabColor(); lab.l = l, lab.a = a, lab.b = b; doc.selection.fill( lab, ColorBlendMode.NORMAL, 100, false ); var saveFile = File( saveFolder.fsName + '/' + n ); doc.saveAs( saveFile, opts, false, Extension.LOWERCASE ); }else{ //writelog() }; }; doc.close( SaveOptions.DONOTSAVECHANGES ); app.preferences.rulerUnits = userUnits;};
function readInCSV( fileObj ) { var fileArray = new Array(); fileObj.open( 'r' ); //fileObj.seek( 0, 0 ); while( ! fileObj.eof ) { var thisLine = fileObj.readln(); var csvArray = thisLine.split( ',' ); fileArray.push( csvArray ); }; fileObj.close(); return fileArray;};