0

So I am looking for a special shortcut or plugin (in either Illustrator or Photoshop) to select a color and export a text version of the color values. For example...

I select a green color, then click a button that then copies the Hex, RGB, and CMYK values of that color and allows me to paste the values in a text box or word doc.

It would really help in creating Brand guidelines when listing off the brand colors

  • What have you tried? What plugins have you looked at? Showing more effort is likely to get you better answers – Zach Saucier May 10 '16 at 2:27
  • So far Ive basically used websites like color-hex.com or colorhexa.com to get values in a text format. I haven't been able to find any plugins that do what Im trying to do, otherwise I would use them. – Aaron R. May 10 '16 at 18:16
3

OK, so... I saw your question and remembered I've been meaning to write a script to do this in Illustrator. So I did it... I havn't tested it much and it could probably be cleaned up a bit but it should work (it does for me with CS6 on OS X)

It takes all your selected swatches and prints the CMYK, RGB and HEX (and name if it's a Spot color) of all those selected swatches to a txt file. I normally have all my 'brand' colors their own color group, so I can just select that group and run the script easily enough.

The txt file gets saved with the same name and in the same folder as your Illustrator file. If your Illustrator file is unsaved, it saves the txt file in your home directory (which is different depending on your OS).

Enjoy!

// Color Modes To Text
// ===================    
// Prints CMYK, RGB and HEX of all selected swatches to a .txt file

// The .txt file is saved with the same file name and in the same folder as your .ai file
// If the .ai file hasn't been saved, the .txt file is saved in your home directory

main();
function main()
{
    var doc = app.activeDocument;
    var selectedSwatches = doc.swatches.getSelected();

    if (selectedSwatches.length > 0)
    {
        var text = "";

        for (var i = 0; i < selectedSwatches.length; i++)
        {
            var swatch = selectedSwatches[i]
            var color = swatch.color;

            // Spot
            if (color.typename == "SpotColor") {
                text += color.spot.name + "\n";
                color = color.spot.color;
            }

            // CMYK Source
            if (color.typename == "CMYKColor")
            {
                // CMYK Values
                text += "C=" + Math.round(color.cyan) + " M=" + Math.round(color.magenta) + " Y=" + Math.round(color.yellow) + " K=" + Math.round(color.black) + "\n";

                // RGB Values
                var rgb = convertColor("CMYK", "RGB", [Math.round(color.cyan), Math.round(color.magenta), Math.round(color.yellow), Math.round(color.black)]);
                text += "R=" + Math.floor(rgb[0]) + " G=" + Math.floor(rgb[1]) + " B=" + Math.floor(rgb[2]) + "\n";

                // HEX Values
                text += rgbToHex(Math.floor(rgb[0]), Math.floor(rgb[1]), Math.floor(rgb[2])) + "\n";
                text += "\n";
            }
            // RGB Source
            else if (color.typename == "RGBColor")
            {
                // CMYK Values
                var cmyk = convertColor("RGB", "CMYK", [Math.round(color.red), Math.round(color.green), Math.round(color.blue)]);
                text += "C=" + Math.round(cmyk[0]) + " M=" + Math.round(cmyk[1]) + " Y=" + Math.round(cmyk[2]) + " K=" + Math.round(cmyk[3]) + "\n";

                // RGB Values
                text += "R=" + Math.floor(color.red) + " G=" + Math.floor(color.green) + " B=" + Math.floor(color.blue) + "\n";

                // HEX Values
                text += rgbToHex(Math.floor(color.red), Math.floor(color.green), Math.floor(color.blue)) + "\n";
                text += "\n";
            }
        }
        saveTxt(text);
    }
    else {
        alert("No Swatches Selected.");
    }
}

function convertColor(src, dest, clrArr)
{
    return app.convertSampleColor(ImageColorSpace[src], clrArr, ImageColorSpace[dest], ColorConvertPurpose.defaultpurpose);
}

function componentToHex(c)
{
    var hex = c.toString(16);
    return hex.length == 1 ? "0" + hex : hex;
}

function rgbToHex(r, g, b)
{
    return "#" + componentToHex(r) + componentToHex(g) + componentToHex(b);
}

function saveTxt(txt)
{
    var name = app.activeDocument.name.replace(/\.[^\.]+$/, '');
    var path = (app.activeDocument.path != "") ? app.activeDocument.path : "~";

    var saveFile = new File(path + "/" + name + ".txt");

    if(saveFile.exists)
        saveFile.remove();

    saveFile.encoding = "UTF8";
    saveFile.open("e", "TEXT");
    saveFile.writeln(txt);
    saveFile.close();

    alert("Saved to File:\n" + saveFile.fullName)
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.