Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Can I set a hotkey for Color Label?

New Here ,
Aug 20, 2024 Aug 20, 2024

Hello everyone,

 

Is it possible to set a hotkey for adding color labels to layers? I like to categorize my layers using different colors, like red, green, and blue. However, I currently have to right-click on each layer and select the color, which is time-consuming.

Is there a way to configure it so that I can click on a layer and press, for example, F1 for a Red Label, F2 for a Blue Label, and so on?

 

Thank you in advance!

🥹🙏🏻💖

TOPICS
Windows
1.6K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Aug 21, 2024 Aug 21, 2024

It appears the only method is to record the action for setting the color label on the current layer, then assign a keyboard shortcut to execute that action.

Translate
Adobe
Community Expert ,
Aug 21, 2024 Aug 21, 2024

It appears the only method is to record the action for setting the color label on the current layer, then assign a keyboard shortcut to execute that action.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 21, 2024 Aug 21, 2024
quote

It appears the only method is to record the action for setting the color label on the current layer, then assign a keyboard shortcut to execute that action.


By @Bojan Živković

 

Same for scripting, which allows keyboard shortcuts that are not F-Key based.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 22, 2024 Aug 22, 2024
async function actionCommands() {
    let command;
    let result;
    let psAction = require("photoshop").action;

    // Set current layer
    command = {"_obj":"set","_target":[{"_enum":"ordinal","_ref":"layer","_value":"targetEnum"}],"to":{"_obj":"layer","color":{"_enum":"color","_value":"blue"}}};
    result = await psAction.batchPlay([command], {});
}

async function runModalFunction() {
    await require("photoshop").core.executeAsModal(actionCommands, {"commandName": "Action Commands"});
}

await runModalFunction();
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 22, 2024 Aug 22, 2024

@Lumigraphics –Hey, nice to see some UXP/BatchPlay!  :]

 

Here it is in legacy ExtendScript:

 

// Set the active layer label color
// "none","red","orange","yellowColor","grain","blue","violet","gray" - new in 2024: "magenta", "seafoam", "indigo", "fuchsia"
setLayerLabelCol("red");

function setLayerLabelCol(labelCol) {
    var c2t = function (s) {
        return app.charIDToTypeID(s);
    };
    var s2t = function (s) {
        return app.stringIDToTypeID(s);
    };
    var descriptor = new ActionDescriptor();
    var descriptor2 = new ActionDescriptor();
    var reference = new ActionReference();
    reference.putEnumerated(s2t("layer"), s2t("ordinal"), s2t("targetEnum"));
    descriptor.putReference(c2t("null"), reference);
    descriptor2.putEnumerated(s2t("color"), s2t("color"), s2t(labelCol));
    descriptor.putObject(s2t("to"), s2t("layer"), descriptor2);
    executeAction(s2t("set"), descriptor, DialogModes.NO);
}

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 23, 2024 Aug 23, 2024

I must confess that was copypasta 😄

This could probably be setup as a persistent panel with buttons using UXP, if it was that important.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 25, 2024 Aug 25, 2024
quote

I must confess that was copypasta 😄

This could probably be setup as a persistent panel with buttons using UXP, if it was that important.


By @Lumigraphics

 

It doesn't matter the source, it's just refreshing to see somebody "taking an interest" in UXP scripting! 

 

Curiously, "yellowColor" remains, however, Adobe have finally changed "grain" to "green".  :]

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 26, 2024 Aug 26, 2024

I'd really like to switch over but who knows. I want to learn enough Lua to write a plugin that fixes the stupid "Enhanced-NR" filenames in Lightroom, and I REALLY want to start learning Swift.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Sep 25, 2024 Sep 25, 2024

How would we amend this script so we could cycle through the colors either forward or backwards?

I like the addition of the colors in 2024, there were needed, but hiding them in a sub menu is really irritating.

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 25, 2024 Sep 25, 2024

Both of the posted scripts only change to the specified color. I'm not sure what you mean by "cycle through" though. Do you want granular selection or sequential assignment, or???

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Sep 25, 2024 Sep 25, 2024

So you assign two keyboard shortcuts, one goes down the list of colors, the other goes up the list of colors

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 25, 2024 Sep 25, 2024

@jackdaw_1066 

 

As @Lumigraphics notes, the current examples only select a single hard-coded colour. New scripts are required to cycle through the list of colours.

 

The script I’m working on cycles forwards each time it is run, then if you hold down the Alt/Option key it cycles backwards (when run from the scripts menu, but NOT by a keyboard shortcut)... But you could assign keyboard shortcuts to two separate scripts if you want a keyboard shortcut to cycle forward or backwards.

 

EDIT: I have posted the 6 scripts, 3 for v2024 and 3 for v2023 or earlier (only tested with v2021).

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Sep 26, 2024 Sep 26, 2024

Thats amazing! Works perfectly on 2024 for me, brilliant work thanks!!!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Sep 26, 2024 Sep 26, 2024

Just to add i've been using this all day, its so handy!!!!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 26, 2024 Sep 26, 2024
LATEST

@jackdaw_1066 

 

Glad it's working well for you!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 26, 2024 Sep 26, 2024

For version 2024 >

Cycle Through Layer Color Labels - Forward v2024.jsx
NOTE: Intended for use with a custom keyboard shortcut when the script is installed into the ...Presets/Scripts folder 

 

/*
Cycle Through Layer Color Labels - Forward v2024.jsx
v1.0 - 26th September 2024, Stephen Marsh
https://community.adobe.com/t5/photoshop-ecosystem-discussions/can-i-set-a-hotkey-for-color-label/td-p/14812505
NOTE: Intended for use with a custom keyboard shortcut when the script is installed into the ...Presets/Scripts folder
*/

#target photoshop

// Ensure that version 2024 or later is being used
var versionNumber = app.version.split(".");
var versionCheck = parseInt(versionNumber[0]);

if (versionCheck < 25) {

    alert("You must use Photoshop 2024 or later to use this script!");

} else {

    // Main Execution: Get current layer color and determine its index
    try {
        // Get the current layer color
        var activeLayerColor = getLayerColour();
        //alert("Current color is: " + activeLayerColor);  // Log the current color

        if (activeLayerColor !== null) {
            // Proceed to set the next color
            setNextLayerLabelCol(activeLayerColor);
        } else {
            //alert("Error: Couldn't retrieve the layer's label color.");
        }
    } catch (e) {
        //alert("Error in main execution: " + e.message);
    }

    // Function to get the active layer color label
    function getLayerColour() {
        try {
            var ref = new ActionReference();
            ref.putEnumerated(charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));
            var desc = executeActionGet(ref);

            if (desc.hasKey(stringIDToTypeID('color'))) {
                var colorID = desc.getEnumerationValue(stringIDToTypeID('color'));
                return typeIDToStringID(colorID); // Return color label as a string
            } else {
                return "none"; // If no color label is found
            }
        } catch (e) {
            //alert("Error retrieving layer color: " + e.message);
            return null;
        }
    }

    // Function to determine index of the current color and set the next color
    function setNextLayerLabelCol(currentColor) {
        // Define colorList as an array (original and new colors)
        var colorList = [
            "none",
            "red",
            "orange",
            "yellowColor",
            "grain", // Green
            "seafoam", // New in 2024
            "blue",
            "indigo", // New in 2024
            "magenta", // New in 2024
            "fuchsia", // New in 2024
            "violet",
            "gray" // Gray
        ];

        try {
            // Debugging the current color
            //alert("Current color before lookup: " + currentColor);

            // Manually find the index of the current color
            var currentIndex = -1;
            for (var i = 0; i < colorList.length; i++) {
                if (colorList[i] === currentColor) {
                    currentIndex = i;
                    break;
                }
            }

            // If the current color is not found, set index to 0
            if (currentIndex === -1) {
                //alert("Error: Current color not found in the list. Setting to 'none'.");
                currentIndex = 0; // Default to 'none' if not found
            } else {
                // Set to next color in the list
                currentIndex = (currentIndex + 1) % colorList.length; // Loop back to start
            }

            var nextColor = colorList[currentIndex];
            //alert("Setting new color to: " + nextColor);  // Log the new color

            // Apply the new layer label color
            if (!app.activeDocument.activeLayer.isBackgroundLayer) {
                setLayerLabelCol(nextColor);
            }
        } catch (e) {
            //alert("Error determining color index: " + e.message);
        }
    }

    // Function to set the new layer label color
    function setLayerLabelCol(labelCol) {
        var c2t = function (s) {
            return app.charIDToTypeID(s);
        };
        var s2t = function (s) {
            return app.stringIDToTypeID(s);
        };

        var descriptor = new ActionDescriptor();
        var reference = new ActionReference();
        reference.putEnumerated(s2t("layer"), s2t("ordinal"), s2t("targetEnum"));
        descriptor.putReference(c2t("null"), reference);

        // Create a descriptor for the color
        var colorDescriptor = new ActionDescriptor();
        try {
            // Use stringIDToTypeID for the new colors
            var colorID = stringIDToTypeID(labelCol); // Convert label to ID

            // Check if the colorID is valid
            if (colorID === undefined) {
                //alert("Invalid color ID for: " + labelCol);
                return; // Exit if the color ID is not valid
            }

            // Debugging color ID
            //alert("Color ID for '" + labelCol + "': " + colorID);

            colorDescriptor.putEnumerated(s2t("color"), s2t("color"), colorID);

            // Apply the new color label to the layer
            descriptor.putObject(s2t("to"), s2t("layer"), colorDescriptor);

            executeAction(s2t("set"), descriptor, DialogModes.NO);
            //alert("Successfully set layer color to: " + labelCol);
        } catch (e) {
            //alert("Error applying color: " + labelCol + ", " + e.message);
        }
    }

}

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 26, 2024 Sep 26, 2024

For version 2024 >

Cycle Through Layer Color Labels - Backward v2024.jsx
NOTE: Intended for use with a custom keyboard shortcut when the script is installed into the ...Presets/Scripts folder 

 

/*
Cycle Through Layer Color Labels - Backward v2024.jsx
v1.0 - 26th September 2024, Stephen Marsh
https://community.adobe.com/t5/photoshop-ecosystem-discussions/can-i-set-a-hotkey-for-color-label/td-p/14812505
NOTE: Intended for use with a custom keyboard shortcut when the script is installed into the ...Presets/Scripts folder
*/

#target photoshop

// Ensure that version 2024 or later is being used
var versionNumber = app.version.split(".");
var versionCheck = parseInt(versionNumber[0]);

if (versionCheck < 25) {

    alert("You must use Photoshop 2024 or later to use this script!");

} else {

    // Main Execution: Get current layer color and determine its index
    try {
        // Get the current layer color
        var activeLayerColor = getLayerColour();
        //alert("Current color is: " + activeLayerColor);  // Log the current color

        if (activeLayerColor !== null) {
            // Proceed to set the next color
            setPreviousLayerLabelCol(activeLayerColor);
        } else {
            //alert("Error: Couldn't retrieve the layer's label color.");
        }
    } catch (e) {
        //alert("Error in main execution: " + e.message);
    }

    // Function to get the active layer color label
    function getLayerColour() {
        try {
            var ref = new ActionReference();
            ref.putEnumerated(charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));
            var desc = executeActionGet(ref);

            if (desc.hasKey(stringIDToTypeID('color'))) {
                var colorID = desc.getEnumerationValue(stringIDToTypeID('color'));
                return typeIDToStringID(colorID); // Return color label as a string
            } else {
                return "none"; // If no color label is found
            }
        } catch (e) {
            //alert("Error retrieving layer color: " + e.message);
            return null;
        }
    }

    // Function to determine index of the current color and set the next color
    function setPreviousLayerLabelCol(currentColor) {
        // Define colorList as an array (original and new colors)
        var colorList = [
            "none",
            "red",
            "orange",
            "yellowColor",
            "grain", // Green
            "seafoam", // New in 2024
            "blue",
            "indigo", // New in 2024
            "magenta", // New in 2024
            "fuchsia", // New in 2024
            "violet",
            "gray" // Gray
        ];

        try {
            // Debugging the current color
            //alert("Current color before lookup: " + currentColor);

            // Manually find the index of the current color
            var currentIndex = -1;
            for (var i = 0; i < colorList.length; i++) {
                if (colorList[i] === currentColor) {
                    currentIndex = i;
                    break;
                }
            }

            // If the current color is not found, set index to the last color
            if (currentIndex === -1) {
                //alert("Error: Current color not found in the list. Setting to 'none'.");
                currentIndex = 0; // Default to 'none' if not found
            } else {
                // Set to the previous color in the list (backward loop)
                currentIndex = (currentIndex - 1 + colorList.length) % colorList.length; // Loop back to the end
            }

            var nextColor = colorList[currentIndex];
            //alert("Setting new color to: " + nextColor);  // Log the new color

            // Apply the new layer label color
            if (!app.activeDocument.activeLayer.isBackgroundLayer) {
                setLayerLabelCol(nextColor);
            }
        } catch (e) {
            //alert("Error determining color index: " + e.message);
        }
    }

    // Function to set the new layer label color
    function setLayerLabelCol(labelCol) {
        var c2t = function (s) {
            return app.charIDToTypeID(s);
        };
        var s2t = function (s) {
            return app.stringIDToTypeID(s);
        };

        var descriptor = new ActionDescriptor();
        var reference = new ActionReference();
        reference.putEnumerated(s2t("layer"), s2t("ordinal"), s2t("targetEnum"));
        descriptor.putReference(c2t("null"), reference);

        // Create a descriptor for the color
        var colorDescriptor = new ActionDescriptor();
        try {
            // Use stringIDToTypeID for the new colors
            var colorID = stringIDToTypeID(labelCol); // Convert label to ID

            // Check if the colorID is valid
            if (colorID === undefined) {
                //alert("Invalid color ID for: " + labelCol);
                return; // Exit if the color ID is not valid
            }

            // Debugging color ID
            //alert("Color ID for '" + labelCol + "': " + colorID);

            colorDescriptor.putEnumerated(s2t("color"), s2t("color"), colorID);

            // Apply the new color label to the layer
            descriptor.putObject(s2t("to"), s2t("layer"), colorDescriptor);

            executeAction(s2t("set"), descriptor, DialogModes.NO);
            //alert("Successfully set layer color to: " + labelCol);
        } catch (e) {
            //alert("Error applying color: " + labelCol + ", " + e.message);
        }
    }

}

 

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 26, 2024 Sep 26, 2024

For version 2024 >

Cycle Through Layer Color Labels - Forward - ALT for Backward v2024.jsx
NOTE: Not intended for use with a keyboard shortcut, only for execution via the script menu or an action. Hold down the alt/opt key to reverse
 
/*
Cycle Through Layer Color Labels - Forward - ALT for Backward v2024.jsx
v1.0 - 26th September 2024, Stephen Marsh
https://community.adobe.com/t5/photoshop-ecosystem-discussions/can-i-set-a-hotkey-for-color-label/td-p/14812505
NOTE: Not intended for use with a keyboard shortcut, only for execution via the script menu or an action. Hold down the alt/opt key to reverse
*/

#target photoshop

// Ensure that version 2024 or later is being used
var versionNumber = app.version.split(".");
var versionCheck = parseInt(versionNumber[0]);

if (versionCheck < 25) {

    alert("You must use Photoshop 2024 or later to use this script!");

} else {

    // Main Execution: Get current layer color and determine its index
    try {
        // Get the current layer color
        var activeLayerColor = getLayerColour();
        //alert("Current color is: " + activeLayerColor);  // Log the current color

        if (activeLayerColor !== null) {
            // Proceed to set the next color
            setNextLayerLabelCol(activeLayerColor);
        } else {
            //alert("Error: Couldn't retrieve the layer's label color.");
        }
    } catch (e) {
        //alert("Error in main execution: " + e.message);
    }

    // Function to get the active layer color label
    function getLayerColour() {
        try {
            var ref = new ActionReference();
            ref.putEnumerated(charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));
            var desc = executeActionGet(ref);

            if (desc.hasKey(stringIDToTypeID('color'))) {
                var colorID = desc.getEnumerationValue(stringIDToTypeID('color'));
                return typeIDToStringID(colorID); // Return color label as a string
            } else {
                return "none"; // If no color label is found
            }
        } catch (e) {
            //alert("Error retrieving layer color: " + e.message);
            return null;
        }
    }

    // Function to determine index of the current color and set the next color
    function setNextLayerLabelCol(currentColor) {
        // Define colorList as an array (original and new colors)
        var colorList = [
            "none",
            "red",
            "orange",
            "yellowColor",
            "grain", // Green
            "seafoam", // New in 2024
            "blue",
            "indigo", // New in 2024
            "magenta", // New in 2024
            "fuchsia", // New in 2024
            "violet",
            "gray" // Gray
        ];

        // Debugging output to check colorList definition
        if (typeof colorList !== "object" || !colorList.length) {
            //alert("Error: colorList is not defined correctly!");
            return; // Exit if colorList is not defined as expected
        }

        try {
            // Find the index of the current color
            var currentIndex = -1;
            for (var i = 0; i < colorList.length; i++) {
                if (colorList[i] === currentColor) {
                    currentIndex = i;
                    break;
                }
            }

            // If the current color is not found, default to the first color
            if (currentIndex === -1) {
                //alert("Error: Current color not found in the list. Setting to 'none'.");
                currentIndex = 0; // Default to 'none' if not found
            } else {
                // Check if the Alt/Opt key is pressed using ScriptUI
                var isAltPressed = ScriptUI.environment.keyboardState.altKey;

                if (isAltPressed) {
                    // Alt/Opt key pressed - reverse loop
                    currentIndex = (currentIndex - 1 + colorList.length) % colorList.length; // Loop back to the end
                } else {
                    // Forward loop
                    currentIndex = (currentIndex + 1) % colorList.length; // Loop back to start
                }
            }

            var nextColor = colorList[currentIndex];
            //alert("Setting new color to: " + nextColor);  // Log the new color

            // Apply the new layer label color
            if (!app.activeDocument.activeLayer.isBackgroundLayer) {
                setLayerLabelCol(nextColor);
            }
        } catch (e) {
            //alert("Error determining color index: " + e.message);
        }
    }

    // Function to set the new layer label color
    function setLayerLabelCol(labelCol) {
        var c2t = function (s) {
            return app.charIDToTypeID(s);
        };
        var s2t = function (s) {
            return app.stringIDToTypeID(s);
        };

        var descriptor = new ActionDescriptor();
        var reference = new ActionReference();
        reference.putEnumerated(s2t("layer"), s2t("ordinal"), s2t("targetEnum"));
        descriptor.putReference(c2t("null"), reference);

        // Create a descriptor for the color
        var colorDescriptor = new ActionDescriptor();
        try {
            // Use stringIDToTypeID for the new colors
            var colorID = stringIDToTypeID(labelCol); // Convert label to ID

            // Check if the colorID is valid
            if (colorID === undefined) {
                //alert("Invalid color ID for: " + labelCol);
                return; // Exit if the color ID is not valid
            }

            // Debugging color ID
            //alert("Color ID for '" + labelCol + "': " + colorID);

            colorDescriptor.putEnumerated(s2t("color"), s2t("color"), colorID);

            // Apply the new color label to the layer
            descriptor.putObject(s2t("to"), s2t("layer"), colorDescriptor);

            executeAction(s2t("set"), descriptor, DialogModes.NO);
            //alert("Successfully set layer color to: " + labelCol);
        } catch (e) {
            //alert("Error applying color: " + labelCol + ", " + e.message);
        }
    }

}

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 26, 2024 Sep 26, 2024

For version 2023 or earlier

Cycle Through Layer Color Labels - Forward.jsx
NOTE: Intended for use with a custom keyboard shortcut when the script is installed into the ...Presets/Scripts folder
 
/*
Cycle Through Layer Color Labels - Forward.jsx
v1.0 - 26th September 2024, Stephen Marsh
https://community.adobe.com/t5/photoshop-ecosystem-discussions/can-i-set-a-hotkey-for-color-label/td-p/14812505
NOTE: Intended for use with a custom keyboard shortcut when the script is installed into the ...Presets/Scripts folder
*/

#target photoshop

// Ensure that version 2023 or earlier is being used
var versionNumber = app.version.split(".");
var versionCheck = parseInt(versionNumber[0]);

if (versionCheck <= 24) {

    // Main Execution: Get current layer color and determine its index
    try {
        // Get the current layer color
        var activeLayerColor = getLayerColour();
        //alert("Current color is: " + activeLayerColor);  // Log the current color

        if (activeLayerColor !== null) {
            // Proceed to set the next color
            setNextLayerLabelCol(activeLayerColor);
        } else {
            //alert("Error: Couldn't retrieve the layer's label color.");
        }
    } catch (e) {
        //alert("Error in main execution: " + e.message);
    }

    // Function to get the active layer color label
    function getLayerColour() {
        try {
            var ref = new ActionReference();
            ref.putEnumerated(charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));
            var desc = executeActionGet(ref);

            if (desc.hasKey(stringIDToTypeID('color'))) {
                var colorID = desc.getEnumerationValue(stringIDToTypeID('color'));
                return typeIDToStringID(colorID); // Return color label as a string
            } else {
                return "none"; // If no color label is found
            }
        } catch (e) {
            //alert("Error retrieving layer color: " + e.message);
            return null;
        }
    }

    // Function to determine index of the current color and set the next color
    function setNextLayerLabelCol(currentColor) {
        // Define colorList as an array (original and new colors)
        var colorList = [
            "none",
            "red",
            "orange",
            "yellowColor", // Yellow
            "grain", // Green
            "blue",
            "violet",
            "gray"
        ];

        try {
            // Debugging the current color
            //alert("Current color before lookup: " + currentColor);

            // Manually find the index of the current color
            var currentIndex = -1;
            for (var i = 0; i < colorList.length; i++) {
                if (colorList[i] === currentColor) {
                    currentIndex = i;
                    break;
                }
            }

            // If the current color is not found, set index to 0
            if (currentIndex === -1) {
                //alert("Error: Current color not found in the list. Setting to 'none'.");
                currentIndex = 0; // Default to 'none' if not found
            } else {
                // Set to next color in the list
                currentIndex = (currentIndex + 1) % colorList.length; // Loop back to start
            }

            var nextColor = colorList[currentIndex];
            //alert("Setting new color to: " + nextColor);  // Log the new color

            // Apply the new layer label color
            if (!app.activeDocument.activeLayer.isBackgroundLayer) {
                setLayerLabelCol(nextColor);
            }
        } catch (e) {
            //alert("Error determining color index: " + e.message);
        }
    }

    // Function to set the new layer label color
    function setLayerLabelCol(labelCol) {
        var c2t = function (s) {
            return app.charIDToTypeID(s);
        };
        var s2t = function (s) {
            return app.stringIDToTypeID(s);
        };

        var descriptor = new ActionDescriptor();
        var reference = new ActionReference();
        reference.putEnumerated(s2t("layer"), s2t("ordinal"), s2t("targetEnum"));
        descriptor.putReference(c2t("null"), reference);

        // Create a descriptor for the color
        var colorDescriptor = new ActionDescriptor();
        try {
            // Use stringIDToTypeID for the new colors
            var colorID = stringIDToTypeID(labelCol); // Convert label to ID

            // Check if the colorID is valid
            if (colorID === undefined) {
                //alert("Invalid color ID for: " + labelCol);
                return; // Exit if the color ID is not valid
            }

            // Debugging color ID
            //alert("Color ID for '" + labelCol + "': " + colorID);

            colorDescriptor.putEnumerated(s2t("color"), s2t("color"), colorID);

            // Apply the new color label to the layer
            descriptor.putObject(s2t("to"), s2t("layer"), colorDescriptor);

            executeAction(s2t("set"), descriptor, DialogModes.NO);
            //alert("Successfully set layer color to: " + labelCol);
        } catch (e) {
            //alert("Error applying color: " + labelCol + ", " + e.message);
        }
    }

} else {

    alert("You must use Photoshop 2023 or earlier to use this script!");

}

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 26, 2024 Sep 26, 2024

For version 2023 or earlier

Cycle Through Layer Color Labels - Backward.jsx
NOTE: Intended for use with a custom keyboard shortcut when the script is installed into the ...Presets/Scripts folder
/*
Cycle Through Layer Color Labels - Backward.jsx
v1.0 - 26th September 2024, Stephen Marsh
https://community.adobe.com/t5/photoshop-ecosystem-discussions/can-i-set-a-hotkey-for-color-label/td-p/14812505
NOTE: Intended for use with a custom keyboard shortcut when the script is installed into the ...Presets/Scripts folder
*/

#target photoshop

// Ensure that version 2023 or earlier is being used
var versionNumber = app.version.split(".");
var versionCheck = parseInt(versionNumber[0]);

if (versionCheck <= 24) {

    // Main Execution: Get current layer color and determine its index
try {
    // Get the current layer color
    var activeLayerColor = getLayerColour();
    //alert("Current color is: " + activeLayerColor);  // Log the current color

    if (activeLayerColor !== null) {
        // Proceed to set the next color
        setPreviousLayerLabelCol(activeLayerColor);
    } else {
        //alert("Error: Couldn't retrieve the layer's label color.");
    }
} catch (e) {
    //alert("Error in main execution: " + e.message);
}

// Function to get the active layer color label
function getLayerColour() {
    try {
        var ref = new ActionReference();
        ref.putEnumerated(charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));
        var desc = executeActionGet(ref);

        if (desc.hasKey(stringIDToTypeID('color'))) {
            var colorID = desc.getEnumerationValue(stringIDToTypeID('color'));
            return typeIDToStringID(colorID);  // Return color label as a string
        } else {
            return "none";  // If no color label is found
        }
    } catch (e) {
        //alert("Error retrieving layer color: " + e.message);
        return null;
    }
}

// Function to determine index of the current color and set the next color
function setPreviousLayerLabelCol(currentColor) {
    // Define colorList as an array (original and new colors)
    var colorList = [
        "none",
        "red",
        "orange",
        "yellowColor", // Yellow
        "grain", // Green
        "blue",
        "violet",
        "gray"
    ];

    try {
        // Debugging the current color
        //alert("Current color before lookup: " + currentColor);
        
        // Manually find the index of the current color
        var currentIndex = -1;
        for (var i = 0; i < colorList.length; i++) {
            if (colorList[i] === currentColor) {
                currentIndex = i;
                break;
            }
        }

        // If the current color is not found, set index to the last color
        if (currentIndex === -1) {
            //alert("Error: Current color not found in the list. Setting to 'none'.");
            currentIndex = 0; // Default to 'none' if not found
        } else {
            // Set to the previous color in the list (backward loop)
            currentIndex = (currentIndex - 1 + colorList.length) % colorList.length; // Loop back to the end
        }

        var nextColor = colorList[currentIndex];
        //alert("Setting new color to: " + nextColor);  // Log the new color

        // Apply the new layer label color
        if (!app.activeDocument.activeLayer.isBackgroundLayer) {
            setLayerLabelCol(nextColor);
        }
    } catch (e) {
        //alert("Error determining color index: " + e.message);
    }
}

// Function to set the new layer label color
function setLayerLabelCol(labelCol) {
    var c2t = function (s) {
        return app.charIDToTypeID(s);
    };
    var s2t = function (s) {
        return app.stringIDToTypeID(s);
    };

    var descriptor = new ActionDescriptor();
    var reference = new ActionReference();
    reference.putEnumerated(s2t("layer"), s2t("ordinal"), s2t("targetEnum"));
    descriptor.putReference(c2t("null"), reference);

    // Create a descriptor for the color
    var colorDescriptor = new ActionDescriptor();
    try {
        // Use stringIDToTypeID for the new colors
        var colorID = stringIDToTypeID(labelCol); // Convert label to ID
        
        // Check if the colorID is valid
        if (colorID === undefined) {
            //alert("Invalid color ID for: " + labelCol);
            return; // Exit if the color ID is not valid
        }

        // Debugging color ID
        //alert("Color ID for '" + labelCol + "': " + colorID);

        colorDescriptor.putEnumerated(s2t("color"), s2t("color"), colorID);

        // Apply the new color label to the layer
        descriptor.putObject(s2t("to"), s2t("layer"), colorDescriptor);
        
        executeAction(s2t("set"), descriptor, DialogModes.NO);
        //alert("Successfully set layer color to: " + labelCol);
    } catch (e) {
        //alert("Error applying color: " + labelCol + ", " + e.message);
    }
}

} else {

    alert("You must use Photoshop 2023 or earlier to use this script!");

}

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 26, 2024 Sep 26, 2024

For version 2023 or earlier

Cycle Through Layer Color Labels - Forward - ALT for Backward.jsx
NOTE: Not intended for use with a keyboard shortcut, only for execution via the script menu or an action. Hold down the alt/opt key to reverse
 
/*
Cycle Through Layer Color Labels - Forward - ALT for Backward.jsx
v1.0 - 26th September 2024, Stephen Marsh
https://community.adobe.com/t5/photoshop-ecosystem-discussions/can-i-set-a-hotkey-for-color-label/td-p/14812505
NOTE: Not intended for use with a keyboard shortcut, only for execution via the script menu or an action. Hold down the alt/opt key to reverse
*/

#target photoshop

// Ensure that version 2023 or earlier is being used
var versionNumber = app.version.split(".");
var versionCheck = parseInt(versionNumber[0]);

if (versionCheck <= 24) {

    // Main Execution: Get current layer color and determine its index
    try {
        // Get the current layer color
        var activeLayerColor = getLayerColour();
        //alert("Current color is: " + activeLayerColor);  // Log the current color

        if (activeLayerColor !== null) {
            // Proceed to set the next color
            setNextLayerLabelCol(activeLayerColor);
        } else {
            //alert("Error: Couldn't retrieve the layer's label color.");
        }
    } catch (e) {
        //alert("Error in main execution: " + e.message);
    }

    // Function to get the active layer color label
    function getLayerColour() {
        try {
            var ref = new ActionReference();
            ref.putEnumerated(charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));
            var desc = executeActionGet(ref);

            if (desc.hasKey(stringIDToTypeID('color'))) {
                var colorID = desc.getEnumerationValue(stringIDToTypeID('color'));
                return typeIDToStringID(colorID); // Return color label as a string
            } else {
                return "none"; // If no color label is found
            }
        } catch (e) {
            //alert("Error retrieving layer color: " + e.message);
            return null;
        }
    }

    // Function to determine index of the current color and set the next color
    function setNextLayerLabelCol(currentColor) {
        // Define colorList as an array (original and new colors)
        var colorList = [
            "none",
            "red",
            "orange",
            "yellowColor", // Yellow
            "grain", // Green
            "blue",
            "violet",
            "gray"
        ];

        // Debugging output to check colorList definition
        if (typeof colorList !== "object" || !colorList.length) {
            //alert("Error: colorList is not defined correctly!");
            return; // Exit if colorList is not defined as expected
        }

        try {
            // Find the index of the current color
            var currentIndex = -1;
            for (var i = 0; i < colorList.length; i++) {
                if (colorList[i] === currentColor) {
                    currentIndex = i;
                    break;
                }
            }

            // If the current color is not found, default to the first color
            if (currentIndex === -1) {
                //alert("Error: Current color not found in the list. Setting to 'none'.");
                currentIndex = 0; // Default to 'none' if not found
            } else {
                // Check if the Alt/Opt key is pressed using ScriptUI
                var isAltPressed = ScriptUI.environment.keyboardState.altKey;

                if (isAltPressed) {
                    // Alt/Opt key pressed - reverse loop
                    currentIndex = (currentIndex - 1 + colorList.length) % colorList.length; // Loop back to the end
                } else {
                    // Forward loop
                    currentIndex = (currentIndex + 1) % colorList.length; // Loop back to start
                }
            }

            var nextColor = colorList[currentIndex];
            //alert("Setting new color to: " + nextColor);  // Log the new color

            // Apply the new layer label color
            if (!app.activeDocument.activeLayer.isBackgroundLayer) {
                setLayerLabelCol(nextColor);
            }
        } catch (e) {
            //alert("Error determining color index: " + e.message);
        }
    }

    // Function to set the new layer label color
    function setLayerLabelCol(labelCol) {
        var c2t = function (s) {
            return app.charIDToTypeID(s);
        };
        var s2t = function (s) {
            return app.stringIDToTypeID(s);
        };

        var descriptor = new ActionDescriptor();
        var reference = new ActionReference();
        reference.putEnumerated(s2t("layer"), s2t("ordinal"), s2t("targetEnum"));
        descriptor.putReference(c2t("null"), reference);

        // Create a descriptor for the color
        var colorDescriptor = new ActionDescriptor();
        try {
            // Use stringIDToTypeID for the new colors
            var colorID = stringIDToTypeID(labelCol); // Convert label to ID

            // Check if the colorID is valid
            if (colorID === undefined) {
                //alert("Invalid color ID for: " + labelCol);
                return; // Exit if the color ID is not valid
            }

            // Debugging color ID
            //alert("Color ID for '" + labelCol + "': " + colorID);

            colorDescriptor.putEnumerated(s2t("color"), s2t("color"), colorID);

            // Apply the new color label to the layer
            descriptor.putObject(s2t("to"), s2t("layer"), colorDescriptor);

            executeAction(s2t("set"), descriptor, DialogModes.NO);
            //alert("Successfully set layer color to: " + labelCol);
        } catch (e) {
            //alert("Error applying color: " + labelCol + ", " + e.message);
        }
    }

} else {

    alert("You must use Photoshop 2023 or earlier to use this script!");

}

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines