Question
Get Working RGB/CMYK in Illustrator with ExtendScript without Open Doc
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);
