Beginner question - buttons not responding

Hi,
I’m a total beginner and I’m trying to create a Photoshop plugin using the UXP tools. I followed a few tutorials, but I get stuck everytime they add a button. I follow the tutorial steps, the button shows up in the panel after reloading, but when I click on it, nothing happens.
Is there anything I’m missing?
Photoshop version: 25.12
UXP Developers tools version: 2.0.1.10

Thank you!

What’s the code for your button?

Here’s the code:

main.js

const { entrypoints } = require("uxp");

  showAlert = () => {
    alert("This is an alert message");
  }

  entrypoints.setup({
    commands: {
      showAlert,
    },
    panels: {
      vanilla: {
        show(node ) {
        }
      }
    }
  });

function scaleLayers() {
  const app = window.require("photoshop").app;

  const activeLayers = app.activeDocument.activeLayers;

  activeLayers.forEach(layer => {
    layer.scale(50, 50);


  })

}

document.getElementById("btnScale").addEventListener("click", showLayerNames);

html:

<!DOCTYPE html>
<html>
<head>
    <script src="main.js"></script> 
    <link rel="stylesheet" href="style.css">   
</head>
<body>
  <sp-heading>Scale Layers</sp-heading>
 
  <footer>
    <sp-button id="btnScale">Scale Layers</sp-button>
  </footer>
</body>
</html>

I was following this tutorial:

But at 9:40 when he demonstrates the example with a button that rescale layers, the button in my plugin doesn’t do anything when I click on it.

I’m pretty sure you should see an error in console about missing showLayerNames function

You’re right! Here’s the message I get in the console:

uxp://uxp-internal/domjs_scripts.js:2 Uncaught ReferenceError: showLayerNames is not defined
    at main.js:32:63
    at e.exports.execScript (uxp://uxp-internal/domjs_scripts.js:2:618363)
    at l (uxp://uxp-internal/domjs_scripts.js:2:621085)
    at uxp://uxp-internal/domjs_scripts.js:2:621282
    at s._executeCallbacks (uxp://uxp-internal/domjs_scripts.js:2:618105)
    at s._executeIfReady (uxp://uxp-internal/domjs_scripts.js:2:618032)
    at Array.<anonymous> (uxp://uxp-internal/domjs_scripts.js:2:618521)
    at s._executeCallbacks (uxp://uxp-internal/domjs_scripts.js:2:618191)
    at s.done (uxp://uxp-internal/domjs_scripts.js:2:617919)
    at Object.s [as loadHtmlContent] (uxp://uxp-internal/domjs_scripts.js:2:76423)

How to fix it?

“showLayerNames is not defined.”
literally it tells the problem. check your function name.
Even if you solve this error, you will find other problems on this code.

1 Like