UXP script Photoshop GET
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);
}
})();
Explore related tutorials & articles
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.
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.
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
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?
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.
Copy link to clipboard
Copied
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.

