Skip to main content
Participant
March 12, 2023
Question

Illustrator Color Settings on Restart

  • March 12, 2023
  • 1 reply
  • 396 views

I found this script and it works on a PC but not on Mac. The goal is to reset color settings on restart. Any help or direction would be appreciated.

 

 

#targetengine main
try {
//for PS and ID, we need the display name of the Color Settings file. This is what you see in Edit>ColorSettings
var colorSettingsFile = "North America Prepress 2";

if (app.name === "Adobe InDesign") {
//InDesign uses app.colorSettings.cmsSettings
app.colorSettings.cmsSettings = colorSettingsFile;
//alert("Color Settings are now: " + app.colorSettings.cmsSettings);
} else if (app.name === "Adobe Photoshop") {
//PS uses app.colorSettings
app.colorSettings = colorSettingsFile;
//alert("Color Settings are now: " + app.colorSettings);
} else if (app.name === "Adobe Illustrator") {
//Special case for AI, which has an array of all available Color Settings.
//We need to find the specific color settings file in the array, then get
//its display name so we can use it to set the Color Settings

//for AI, we need the file name of the specific Color Settings file you want to select.
var settingFile = getAIColorSettingFile('North America Prepress.csf');

if (settingFile) {
app.loadColorSettings(settingFile);
//alert("Color Settings are now: " + settingFile.displayName);
}

}

//this function finds the Display Name of the Color Settings file and returns that file.
function getAIColorSettingFile(name) {
var settingIdx = app.colorSettingsList.length - 1;
var matchToFileLowerCaseName = name.toLowerCase();
var settingFile = null;
while (!settingFile && settingIdx >= 0) {
settingFile = app.colorSettingsList[settingIdx];
var settingFileLowerCaseName = settingFile.displayName.toLowerCase();
if (settingFileLowerCaseName != matchToFileLowerCaseName) {
settingFile = null;
settingIdx--;
}
}

return settingFile;
}

} catch (e) {
alert("Could not set Color Settings to " + colorSettingsFile, "Color Setting Warning", true);
}

This topic has been closed for replies.

1 reply

m1b
Community Expert
Community Expert
March 14, 2023

Hi @Eric285076055rg9, I'm using MacOS and I can help. I've had a look at your code made some changes to make it work for MacOS. I *think* what I've done should work on Windows, too, but I can't test, so let me know.

try {
    //for PS and ID, we need the display name of the Color Settings file. This is what you see in Edit>ColorSettings
    var colorSettingsDisplayName = "North America Prepress 2",
        colorSettingsNameMatcher = /^North America Prepress/i;

    if (app.name === "Adobe InDesign") {
        //InDesign uses app.colorSettings.cmsSettings
        app.colorSettings.cmsSettings = colorSettingsDisplayName;
        //alert("Color Settings are now: " + app.colorSettings.cmsSettings);
    } else if (app.name === "Adobe Photoshop") {
        //PS uses app.colorSettings
        app.colorSettings = colorSettingsDisplayName;
        //alert("Color Settings are now: " + app.colorSettings);
    } else if (app.name === "Adobe Illustrator") {
        //for AI, we need to search through the list of Color Settings files
        var colorSettingsFile = getAIColorSettingFile(colorSettingsNameMatcher);
        if (colorSettingsFile) {
            app.loadColorSettings(colorSettingsFile);
            alert("Color Settings are now: " + decodeURIComponent(colorSettingsFile.name));
        }
    }

    //this function finds the Display Name of the Color Settings file and returns that file.
    function getAIColorSettingFile(matcher) {
        var colorSettingsList = app.colorSettingsList;
        for (var i = 0; i < colorSettingsList.length; i++) {
            var colorSettingsFileName = decodeURIComponent(colorSettingsList[i].name);
            if (matcher.test(colorSettingsFileName))
                return colorSettingsList[i];
        }
    }

} catch (e) {
    alert("Could not set Color Settings to " + colorSettingsDisplayName + ". (" + e.message + ")", "Color Setting Warning", true);
}

 

Here's some notes about what I did:

1. It seems that the color settings files in Illustrator on Mac don't have a displayName property (not all Files do, so you can't rely on it!) so I used the name property, decoded from the URI encoding. This is reliable I think.

2. I re-structured the getAIColorSettingsFile function so that it takes a RegExp to match the filename with. So colorSettingsNameMatcher is a RegExp literal that just matches any string starting with "North American Prepress" and is case insensitive (that's the "i" flag).

 

I tested in Illustrator 17.3.1 on MacOS 13.2.1 and it worked as expected.

- Mark