Skip to main content
Inspiring
November 17, 2024
Answered

Determine whether the action exists

  • November 17, 2024
  • 1 reply
  • 292 views

Hi, friends, I would like to ask how to check if an action exists in Photoshop. For example, if my action set is named 'Default Actions1' and the action is named 'Molten Lead2', how can I use a JSX script to check if 'Default Actions1' exists, and if 'Molten Lead2' exists? Thank you, everyone.

This topic has been closed for replies.
Correct answer AlanGilbertson

This may not be elegant, but it does what you're asking for.

function actionExists(actionSet, actionName) {
    var actionSetExists = false;
    var actionExists = false;

    var actionSetRef = new ActionReference();
    actionSetRef.putName(charIDToTypeID("ASet"), actionSet);

    try {
        var actionSetDesc = executeActionGet(actionSetRef);
        actionSetExists = true;

        var actionRef = new ActionReference();
        actionRef.putName(charIDToTypeID("Actn"), actionName);
        actionRef.putIndex(charIDToTypeID("ASet"), actionSetDesc.getInteger(charIDToTypeID("ItmI")));

        try {
            executeActionGet(actionRef);
            actionExists = true;
        } catch (e) {
            actionExists = false;
        }
    } catch (e) {
        actionSetExists = false;
    }

    return { actionSetExists: actionSetExists, actionExists: actionExists };
}

var actionSet = prompt("Enter the name of the Action Set:");
var actionName = prompt("Enter the name of the Action:");

var result = actionExists(actionSet, actionName);
alert('Action Set: ' + actionSet + ' Exists: ' + result.actionSetExists + '\nAction: ' + actionName + ' Exists: ' + result.actionExists);

 Thank Microsoft Copilot. 🙂 

1 reply

AlanGilbertson
Community Expert
AlanGilbertsonCommunity ExpertCorrect answer
Community Expert
November 17, 2024

This may not be elegant, but it does what you're asking for.

function actionExists(actionSet, actionName) {
    var actionSetExists = false;
    var actionExists = false;

    var actionSetRef = new ActionReference();
    actionSetRef.putName(charIDToTypeID("ASet"), actionSet);

    try {
        var actionSetDesc = executeActionGet(actionSetRef);
        actionSetExists = true;

        var actionRef = new ActionReference();
        actionRef.putName(charIDToTypeID("Actn"), actionName);
        actionRef.putIndex(charIDToTypeID("ASet"), actionSetDesc.getInteger(charIDToTypeID("ItmI")));

        try {
            executeActionGet(actionRef);
            actionExists = true;
        } catch (e) {
            actionExists = false;
        }
    } catch (e) {
        actionSetExists = false;
    }

    return { actionSetExists: actionSetExists, actionExists: actionExists };
}

var actionSet = prompt("Enter the name of the Action Set:");
var actionName = prompt("Enter the name of the Action:");

var result = actionExists(actionSet, actionName);
alert('Action Set: ' + actionSet + ' Exists: ' + result.actionSetExists + '\nAction: ' + actionName + ' Exists: ' + result.actionExists);

 Thank Microsoft Copilot. 🙂 

Inspiring
November 17, 2024

Thank you, it works! I really appreciate it