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

UXP script Photoshop GET

Community Beginner ,
Mar 27, 2023 Mar 27, 2023

Copy link to clipboard

Copied

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);
}
})();

TOPICS
Actions and scripting

Views

493

Translate

Translate

Report

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
Guide ,
Mar 28, 2023 Mar 28, 2023

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

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 Beginner ,
Mar 29, 2023 Mar 29, 2023

Copy link to clipboard

Copied

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; }

Votes

Translate

Translate

Report

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
Guide ,
Mar 29, 2023 Mar 29, 2023

Copy link to clipboard

Copied

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

 

Votes

Translate

Translate

Report

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 Beginner ,
Mar 29, 2023 Mar 29, 2023

Copy link to clipboard

Copied

Thanks a lot, this works great.

I have another question, is it possible to add new button to the Actions palette in UXP? Maybe next to play?

Votes

Translate

Translate

Report

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
Guide ,
Mar 29, 2023 Mar 29, 2023

Copy link to clipboard

Copied

You can't change Photoshop's standard panels, but you can write a new panel with the functionality you need.

 

There is a workaround - you can write a separate action that will run the script. In this case, the script will do what you need. Not sure if UXP scripts support writing to actions, but it is possible with old *.jsx scripts.

Votes

Translate

Translate

Report

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 Beginner ,
Mar 30, 2023 Mar 30, 2023

Copy link to clipboard

Copied

LATEST

Thanks, I thought it might work with UXP. So is there no possibility to add a mouse right click menu? The whole new panel takes up too much space and the keyboard shortcut is not suitable for this use.

Votes

Translate

Translate

Report

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