Changing Colors in Illustrator with Javascript

I'm very new to javascript and I am writing a script to find all pathItems of a specified fill color and change them to another fill color. This must be done in RGB or hex without using swatches. So far I've put together bits of other scripts I found but I'm running into a lot of errors. Here is what I have so far:

var myDoc =app.activeDocument
var fillRGBColor = function (pathItem){
    var fillColor = new Array();
    fillColor[0] =;
    fillColor[1] =;
    fillColor[2] =;
    return fillColor;

var pathItems = myDoc.pathItems;
for (i=0; i<pathItems.length; i++){
    fillColor[255,255,255] ==fillColor[50,50,50];

Thank you!



I needed this same question answered, but the existing answer was incomplete. Here is a full working solution. You specify the "from" RGB and the "to" RGB colors and call fillRGBColor for as many colors you need to change.

The next step is to figure out how to automate this script for more than 1 illustrator file :)

var fillRGBColor = function (pathItems, fr,fg,fb,tr,tg,tb){
    for (var i=0; i < pathItems.length; i++) {

        if (pathItems[i] == fr
           && pathItems[i] == fg
           && pathItems[i] == fb) {
                pathItems[i] = tr;
                pathItems[i] = tg;
                pathItems[i] = tb;


fillRGBColor(app.activeDocument.pathItems, 20, 20, 20, 50, 50, 50);

Indeed you have a lot of erros in your script. Looking at the type of errors I suggest you to read Adobe Illustrator CS5 Reference: JavaScript or any JavaScript tutorial.

In any case you can reduce your JavaScript errors by my modified version of your code.

var fillRGBColor = function (pathItems, r, g, b){
    for (var i=0; i < pathItems.length; i++) {
        pathItems[i] = r;
        pathItems[i] = g;
        pathItems[i] = b;

fillRGBColor(app.activeDocument.pathItems, 50, 50, 50);


Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.