Illustrator spot gradients script

I was going to put a download on this blog that contains a swatch library of gradients using a certain color management systems spot colors. There would have been over a thousand gradients which you could have accessed in Adobe Illustrator or wherever you like to keep your swatch libraries.

But I thought that the high mucky mucks at said color management system company might object on some legal grounds, and I was right. They wrote to me as if to say cease and desist. Even though you can download their color charts from any printer (and I don’t suppose these printers pay licensing fees) and EVEN THOUGH the swatch library might encourage more use of their inks, they thought it best that I not provide you with this tool.

Little did they know that the way I made this gradient swatch library was through Applescript. And since Applescript for Illustrator references only “spot colors,” and not particular spot colors, I can instead provide you with the script so that you can make your own gradient swatch library.

In Illustrator, you can make any color a spot color, including RGB colors, CMYK colors, and HSV colors, so you may want to make a bunch of color swatches first, then use the script below. Just make a color swatch using the contextual menu on the Swatches panel, and set the Color Type to Spot Color.


This script will make a shiny gradient of every spot color in an open document. The gradients will look something like this:


You can easily turn the gradient document you create into a swatch library when you save it.

Here is the script. Copy it from this page and paste it into Script Editor, which is a free application that comes with every Mac:

tell application "Adobe Illustrator"
tell current document
repeat with i from 1 to (count of spots)
set gradientName to name of spot i & "_GS" --this names the gradient after the spot color name and appends "_GS" to it, as in "My Orange Spot_GS". GS stands for Gradient Shiny, since this script makes a shiny gradient of each spot color.
set colorInfor to spot i
if not (exists gradient gradientName in current document) then
set entireGradient to {entire gradient:{{class:gradient stop info, midpoint:56.0, ramp point:0.0, color:{class:spot color info, tint:25.0, spot:colorInfor}}, {class:gradient stop info, midpoint:55.0, ramp point:1.75, color:{class:spot color info, tint:45.0, spot:colorInfor}}, {class:gradient stop info, midpoint:50.0, ramp point:27.0, color:{class:spot color info, tint:88.0, spot:colorInfor}}, {class:gradient stop info, midpoint:57.0, ramp point:55.0, color:{class:spot color info, tint:10.0, spot:colorInfor}}, {class:gradient stop info, midpoint:50.0, ramp point:75.0, color:{class:spot color info, tint:75.0, spot:colorInfor}}, {class:gradient stop info, midpoint:50.0, ramp point:99, color:{class:spot color info, tint:100.0, spot:colorInfor}}, {class:gradient stop info, midpoint:50.0, ramp point:100.0, color:{class:spot color info, tint:15.0, spot:colorInfor}}}}
set gradientRef to make new gradient with properties {name:gradientName, gradient type:linear, entire gradient:entireGradient}
end if
end repeat
end tell
end tell

How to use the script:
Open a new document in Illustrator. Do not draw anything, or put any guides on any layer. Create spot colors using the Swatches panel. Or just drag some spots from one of the included swatch libraries. If you add lots of spots or you don’t have at least a gig of RAM, this script will take a long time to run. When you are done, simply delete the spot colors, leaving the gradients, and save the doc as an .ai file. Then put this file in Illustrator’s gradient swatches folder: /Applications/Adobe Illustrator CS3/Presets/Swatches/Gradients. Feel free to use this script and modify it to your liking, but don’t publish it as your own work. To cite it, just reference the web page you saw it on.

Note: I use Applescript as a tool to help me better my Mac production work. I don’t always put everything into a script when I’m the only user, or in this case, when I’m going to run the script maybe 1 or 2 times. If this was a script that I might save as an application for distribution, I’d put in a test to make sure the user had an Illustrator document open, then to make sure there were no page items on it, and I might even have the script name and close the .ai file.

Next time, I’m going to get back to Applescripting basics, but I just wanted you to have something you can immediately put to good use.


About this entry