Skip to main content
Inspiring
February 11, 2026
Question

Get Working RGB/CMYK in Illustrator with ExtendScript without Open Doc

  • February 11, 2026
  • 2 replies
  • 78 views

Is there a way to get the working CMYK and RGB profile names in Adobe Illustator with ExtendScript without relying on an open docuement so that I don’t have to see the window flashing?

Below is the best I could come up with:
 

function getProfile(targetMode) {

if (targetMode !== "RGB" && targetMode !== "CMYK") {
targetMode = "CMYK";
}

var originalDoc = null;

if (app.documents.length > 0) {
originalDoc = app.activeDocument;
}

if (originalDoc) {

if (
(targetMode === "RGB" && originalDoc.documentColorSpace === DocumentColorSpace.RGB) ||
(targetMode === "CMYK" && originalDoc.documentColorSpace === DocumentColorSpace.CMYK)
) {
return originalDoc.colorProfileName;
}
}

var docColorSpace = (targetMode === "CMYK")
? DocumentColorSpace.CMYK
: DocumentColorSpace.RGB;

var tempDoc = app.documents.add(docColorSpace, 1, 1);

var profile = tempDoc.colorProfileName;

if (originalDoc) {
originalDoc.activate();
}

tempDoc.close(SaveOptions.DONOTSAVECHANGES);

return profile;
}

var profileRGB = getProfile("RGB");
var profileCMYK = getProfile("CMYK");
alert("\nRGB Profile:\n" + profileRGB + "\n\nCMYK Profile:\n" + profileCMYK);

 

2 replies

CarlosCanto
Community Expert
Community Expert
February 15, 2026

oops, my bad, I misunderstood the assignment.

 

try this version, if you start with an open document, the script won't need to create the temp doc

 

// get color profiles, both rgb and cmyk
// carlos canto

function getProfile() {

var deleteDoc = false;

if (app.documents.length > 0) {
var doc = app.activeDocument;
}
else {
var doc = app.documents.add(DocumentColorSpace.CMYK, 1, 1);
deleteDoc = true;
}

var order = [0, 1]; // use to tell whether doc is rgb or cmyk and to switch color modes
var colorSpaces = [DocumentColorSpace.RGB, DocumentColorSpace.CMYK];
var commands = ["doc-color-rgb", "doc-color-cmyk"];
var profiles = [0,1];

// get color mode and profile
var colorSpace = activeDocument.documentColorSpace;
var profile = activeDocument.colorProfileName;

// save the profile in the righ order
if (colorSpace == colorSpaces[1]) {
order.reverse();
profiles[1] = profile;
}
else {
profiles[0] = profile;
}

// change color mode
app.executeMenuCommand (commands[order[1]]);

profiles[order[1]] = activeDocument.colorProfileName;

// reverse color mode to its original mode
app.executeMenuCommand (commands[order[0]]);

// delete temp doc if any
if (deleteDoc) {
activeDocument.close(SaveOptions.DONOTSAVECHANGES);
}

return profiles;
}

var profiles = getProfile();

alert("\nRGB Profile:\n" + profiles[0] + "\n\nCMYK Profile:\n" + profiles[1]);

 

Chris.SAuthor
Inspiring
February 15, 2026

Nice! Better than mine. :-)

I don’t suppose there’s a way to get these from current Color Settings so we don’t have to rely on an open doc or creating a doc?

CarlosCanto
Community Expert
Community Expert
February 15, 2026

let me check if that info is saved in the settings

CarlosCanto
Community Expert
Community Expert
February 13, 2026

Here’s one way to get the document color mode without opening the files. If your ai files have swatches in them, we could use the swatches color mode in the XMP metadata.

Here’s a working Illustrator sample script. I have plenty of comments let me know if you have additional questions

 

place a couple of ai files in a folder before running the script

// get file color mode without opening the file
// carlos canto 2/12/26

/* method
- select folder
- get ai files
- get xmp
- serialize xmp object into String
- convert string to XML
- get first Colorant (color) Mode ("xmpG:mode") - Colorants are swatches in the document
*/

function main() {
//var f = new File(File.openDialog("chose file"));
var aiFolder = new Folder(Folder.selectDialog ("Select Folder with Illustrator Files"));

//var aiFolder = "/c/temp";

// load the XMPScript library
if (ExternalObject.AdobeXMPScript == undefined)
ExternalObject.AdobeXMPScript = new ExternalObject('lib:AdobeXMPScript');

// go through the files in the folder
var aiFiles = aiFolder.getFiles("*.ai");

for (f in aiFiles) {
var file = aiFiles[f];

// applies only to files, not to folders
if (file instanceof File) {
var xmpFile = new XMPFile(file.fsName, XMPConst.UNKNOWN, XMPConst.OPEN_FOR_READ);
var xmp = xmpFile.getXMP();

var xmpString = xmp.serialize();

xmpFile.closeFile(XMPConst.CLOSE_UPDATE_SAFELY);

var xmlObj = new XML(xmpString);
var swatchesMode = xmlObj.descendants("xmpG:mode");

alert (file.fsName + "\n\nColor Mode: " + swatchesMode[0]);

}
}
}

main();

 

Chris.SAuthor
Inspiring
February 14, 2026

Thank you Carlos. Not quite the right solution for the application. For more context, the reason I want the profiles (working CMYK/RGB) is to display them in a dialog that will do conversions between them within Illustrator and create a document with them. This will help the user know if they are in the right space to get more accurate results out of the conversions. My solution was the best I could come up with, but not a fan of the flashing.
 

I could base on the .csf file as well, but that's not as reliable as the user could manually change the working spaces without changing the color settings and they could have custom color settings that I wouldn't know the RGB or CMYK ICC profiles associated with them via a LUT.