Hi friends, I’m new here and I’m kind of tentatively trying to familiarize myself with UXP plugins, but I’ve been having a lot of difficulties.
I managed to make a basic structure with some buttons, but I couldn’t call the index.js functions that are actions converted into the native file.json of the latest versions of Photoshop.
Can anyone point me to a solution.
Here is the index.html file
<!DOCTYPE html>
<html>
<head>
<script src="index.js"></script>
<link rel="stylesheet" href="index.css">
</head>
<body>
<div id="opendoclist"></div>
<sp-action-button onClick='runScript("Remove saturation");' style='left:20px;top:20px;width:150px;height:24px; font-size: 12px; ' >Remove saturation</sp-action-button>
<sp-action-button onClick='runScript("Copy Layer");' style='left:20px;top:20px;width:150px;height:24px; font-size: 12px; ' >Copy Layer</sp-action-button>
<sp-action-button onClick='runScript("Flip horizontal");' style='left:20px;top:20px;width:150px;height:24px; font-size: 12px; ' >Flip layer horizontal</sp-action-button>
<div id="opendoclist"></div>
</body>
</html>
Here is the index.js file
const app = require("photoshop").app;
const action = require("photoshop").action;
const host = require("uxp").host;
const {entrypoints} = require("uxp");
function runScript(func, arg) {
if(!app.documents.length) return;
runScriptAsync(func, arg);
}
async function runScriptAsync(func, arg) {
switch (func) {
case "Remove saturation": {
app.showAlert("Remove saturation");
await action.batchPlay([{"_obj":"hueSaturation","adjustment":[{"_obj":"hueSatAdjustmentV2","hue":0,"lightness":0,"saturation":-100}],"colorize":false,"presetKind":{"_enum":"presetKindType","_value":"presetKindCustom"}}], { });
};
break;
case "Copy Layer": {
app.showAlert("Copy Layer");
await action.batchPlay([{"_obj":"copyToLayer"}], { });
};
break;
case "Flip horizontal": {
app.showAlert("Flip layer horizontal");
await layer.flip("horizontal");
};
break;
}
}
Link do plugin;
https://drive.google.com/drive/folders/1xcHxPA-LXOAjxKHRI-fJNynHJ2PUgy5h
thank you for your attention