Skip to main content
Known Participant
March 27, 2023
Question

UXP script Photoshop GET

  • March 27, 2023
  • 1 reply
  • 1291 views

Please help, I'm trying to find out the currently selected action. The GET function does not work.

async function getSelectedAction() {
const batchPlay = require('photoshop').action.batchPlay;

const result = await batchPlay(
[
{
"_obj": "get",
"_target": [
{
"_property": "property"
},
{
"_ref": "action",
"_name": "selected"
}
],
"_options": {
"dialogOptions": "dontDisplay"
}
}
],
{
"synchronousExecution": true
}
);

const selectedAction = {
actionSetName: result[0].actionSet._name,
actionName: result[0].action._name
};

return selectedAction;
}

(async () => {
try {
const selectedAction = await getSelectedAction();
console.log('Selected action:', selectedAction);
} catch (error) {
console.error('Error:', error);
}
})();

This topic has been closed for replies.

1 reply

Legend
March 28, 2023

Where did you find that you can get the name of the active action using the "selected" property? 🤔 🤔

 

async function getSelectedAction() {
    const batchPlay = require('photoshop').action.batchPlay;
    const result = await batchPlay(
        [
            {
                "_obj": "get",
                "_target": [
                       {
                         _ref: "action", _enum: "ordinal", _value: "targetEnum"
                    }
                ],
                "_options": {
                    "dialogOptions": "dontDisplay"
                }
            }
        ],
        {
            "synchronousExecution": true
        }
    );

    const selectedAction = {
        selectedAction: result[0].name,
        selectedActionSet: result[0].parentName
    };

    return selectedAction;
}

(async () => {
    try {
        const selectedAction = await getSelectedAction();
        console.log('Selected action:', selectedAction);
    } catch (error) {
        console.error('Error:', error);
    }
})();

 

 * it should be understood that there are several border states that need to be taken into account and processed separately: a) if an ActionSet is selected, b) if a command inside an action is selected.

Known Participant
March 29, 2023

Thanks for the reply, but unfortunately, this isn't working. It runs without errors, but returns nothing even though the function is selected. I need to rewrite the following two functions into UXP from CEP, but I can't get it to work.

I tried different ways and it didn't work.
 
function get_curr_action() {
    try {
        var r = new ActionReference();
        r.putEnumerated(stringIDToTypeID("action"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
        var ret = executeActionGet(r);
        var act_idx = ret.getString(stringIDToTypeID("itemIndex"));
        var act_name = ret.getString(stringIDToTypeID("name"));
        var set_name = ret.getString(stringIDToTypeID("parentName"));
        var set_idx = ret.getString(stringIDToTypeID("parentIndex"));
        var r = new ActionReference();
        r.putIndex(stringIDToTypeID("action"), act_idx);
        r.putIndex(stringIDToTypeID("actionSet"), set_idx);
        ret = executeActionGet(r);
        var act_name2 = ret.getString(stringIDToTypeID("name"));
        var set_name2 = ret.getString(stringIDToTypeID("parentName"));
        return [act_name2];
        return null
    }
    catch (e) { return null; }
}
 
 
function get_curr_actionAndSet() {
    try {
        var r = new ActionReference();
        r.putEnumerated(stringIDToTypeID("action"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
        var ret = executeActionGet(r);
        var act_idx = ret.getString(stringIDToTypeID("itemIndex"));
        var act_name = ret.getString(stringIDToTypeID("name"));
        var set_name = ret.getString(stringIDToTypeID("parentName"));
        var set_idx = ret.getString(stringIDToTypeID("parentIndex"));
        var r = new ActionReference();
        r.putIndex(stringIDToTypeID("action"), act_idx);
        r.putIndex(stringIDToTypeID("actionSet"), set_idx);
        ret = executeActionGet(r);
        var act_name2 = ret.getString(stringIDToTypeID("name"));
        var set_name2 = ret.getString(stringIDToTypeID("parentName"));
        if (act_name2 == act_name && set_name == set_name2) return [set_name, act_name];
        return null
    }
    catch (e) { return null; }
Legend
March 29, 2023

Try to make all functions synchronous

 

 function getSelectedAction() {
    const batchPlay = require('photoshop').action.batchPlay;
    const result =  batchPlay(
        [
            {
                "_obj": "get",
                "_target": [
                       {
                         _ref: "action", _enum: "ordinal", _value: "targetEnum"
                    }
                ],
                "_options": {
                    "dialogOptions": "dontDisplay"
                }
            }
        ],
        {
            "synchronousExecution": true
        }
    );

    const selectedAction = {
        selectedAction: result[0].name,
        selectedActionSet: result[0].parentName
    };

    return selectedAction;
}


    try {
        const selectedAction = getSelectedAction();
        console.log('Selected action:', selectedAction);
    } catch (error) {
        console.error('Error:', error);
    }

In any case, I would advise you to visit the community creativeclouddeveloper.com which is focused on UXP