Where am I going wrong when calling functions?

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>
    <script src="index.js"></script>    
    <link rel="stylesheet" href="index.css">
    <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>

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"}}], { });
	case "Copy Layer": {
				app.showAlert("Copy Layer");
				await action.batchPlay([{"_obj":"copyToLayer"}], { });
		case "Flip horizontal": {
			app.showAlert("Flip layer horizontal");
			await layer.flip("horizontal");

Link do plugin;

thank you for your attention

Hi @PS-fxrios

I took a look at your code and you’ll have to define a target layer with which you want to apply each action on.

Let me know if you have other questions.



1 Like

Hi @amandah , would the definition layer you refer to be the “selected” active layer?
See this video for better understanding.

Did you check Console for errors? I would bet it would say something about modal execution. I believe you need to wrap your BP actions into executeAsModal()

Also, you don’t have layer defined at all for the 3rd action


Hi @Karmalakas , thanks for the suggestion. I confess that I still get lost about checking the console for errors.
I will check everything! If I can get this to work, then I’ll come back and post the result and I’ll also make the plugin folder available for those who, like me, are having trouble getting started.