This is the last time I ask the question about Applescript - I see that this topic is unpopular since none of my questions has been answered. Probably I'm on the wrong way, but scripting for Illustrator seems to be very interesting and useful.

I found the way to set the color of a layer to RGB color -

set color of current layer in current document to {red:45.0, green:34.0, blue:34.0}

however, when I immediately execute this line of code -

set currentColor to color of current layer in current document

In the RESULTS window I get long numbers like these -

{class:RGB color info, red:45.000001117587, green:34.000001773238, blue:34.000001773238}

Thus, I cannot perform comparing operation between the colors.

Any suggestions about color formatting, rounding the numbers/totals to the way I can compare current color with desirable one.

  • You should try the Adobe forums. They have some guys in there that LOVE Apple Script.
    – Confused
    Feb 17, 2014 at 0:25
  • Have you thought about asking on the Apple Stack Exchange? May 25, 2014 at 17:04
  • @Gramps Actually, I solved the issue and created the script. No one was interested in that, so I did not post the answer...
    – Ilan
    May 25, 2014 at 17:49
  • I would love to see it and I would post it as an answer. I would surely +1 for it. May 25, 2014 at 17:49
  • @Gramps done special for you
    – Ilan
    May 25, 2014 at 17:57

2 Answers 2


So, in computer programming terms, the kind of numbers you have are called floating point numbers (sometimes they're called real numbers, too). The kind of number that you want is called an integer. To convert a floating point number to an integer, you need to use the magic phrase as integer when getting your number.

It works like this:

set currentColor to color of current layer in current document
set redValue to red of currentColor as integer

Now you should get 45 for your red, not 45.000001117587.

This tutorial gives more information about the various types of data in AppleScript.

P.S. – You might have better luck getting answers to programming questions at Stack Overflow


I post the answer with the whole script, because Gramps asked for. This script recolors the layer label color to provided RGB code - reddish

tell application "Adobe Illustrator" 
  set layersCounter to count layers in current document
  display dialog "In current document there are " & layersCounter & " layers." & "Recolor layers label?"
  repeat until (layersCounter = 0)
  set color of layer layersCounter in current document to {red:255, blue:11, green:15}
  set layersCounter to layersCounter - 1
  end repeat
  end tell

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.