I’m working on a plugin whose purpose is to save cutting presets dynamically, but for this to be possible it is essential that the values are added to the Cut tool option bar programmatically. I did some research here in the community and saw that this is probably possible.
Illustration: Desired result.
Here is my code, but I don’t know what I’m doing wrong as nothing happens when the script is run.
const batchPlay = require("photoshop").action.batchPlay;
// GET TOOL OPTIONS
async function getCurrentToolOptions () {
const result = await batchPlay(
[
{
"_obj": "get",
"_target": [
{
"_property": "currentToolOptions"
},
{
"_ref": "application",
"_enum": "ordinal",
"_value": "targetEnum"
}
],
"_options": {
"dialogOptions": "dontDisplay"
}
}
],{
"synchronousExecution": false
});
return result[0].currentToolOptions;
}
// SET TOOL OPTIONS
async function setCurrentToolOptions(currenttooloptions) {
const result = await batchPlay(
[
{
"_obj": "set",
"_target": [
{
"_ref": "cropTool"
}
],
"to": currenttooloptions
}
],{
"synchronousExecution": false
});
}
async function optionCropWH() {
try {
await core.executeAsModal( async() => {
let inputs = await getCurrentToolOptions();
inputs.$CrpO.$CrHV._value = 15 +"cm";
inputs.$CrpO.$CrWV._value = 21+"cm";
await setCurrentToolOptions(inputs);
})
} catch (error) {alert(error)}
}
optionCropWH()
