Skip to main content
Participant
March 29, 2023
Answered

Error: Expected: ; when drag and dropping .JSX

  • March 29, 2023
  • 1 reply
  • 1110 views
I wrote a script for turning on and off layer combinations and exporting. 
The issue I have now is, the script works when I hit Load on UXP tool, and photoshop executes all the functions, but when I drag and drop it as a .jsx into photoshop, it throws all kinds of errors:
 
For example, this line with the "for...) {" code is throwing: Error 25: Expected: ;.
 
for (let i=0; i<max; i++) {
     //some code to turn on layers
    }
 
 Any async functions throws this error: Error 25: Expected: ;.
 
async function makelyrvis(layer) {
    await window.require("photoshop").core.executeAsModal( () => { 
      layer.visible = true;
    });
}
 
I tried making these functions not async, and got this: Error 23: ) does not have a value. 
For the line with "window.require..."
 
function makelyrvis(layer) { 
  window.require("photoshop").core.executeAsModal( () => {
      layer.visible = true;
    });
}
 
Like I said, the code runs completely fine from UXP Tool, these errors only happen when I use the jsx drag and drop.
The only reason I'm even trying drag and drop is because I can't get the export part of the script to work from UXP tool. IE:
 
function savePNG(layerName) {
  displayDialogs = DialogModes.NO
if (BridgeTalk.appName == "photoshop") {
    app.bringToFront;
}
var newFile = new File("D:/Temp/" + layerName + ".png");
 
  var pngOptions = new PNGSaveOptions();
  pngOptions.compression = 0
  pngOptions.interlaced = false;
  app.activeDocument.saveAs(newFile, pngOptions, true, Extension.LOWERCASE);
}
 
This piece of code won't run in UXP tool, but if I put it by itself in a jsx and drag and drop it into photoshop, it runs fine.
 
So I guess what I'm asking is, how can I make all my code run either with jsx drag and drop, or with UXP tool? 
 
This topic has been closed for replies.
Correct answer jazz-y

*.jsx are scripts written in ExtendScript, an old scripting engine

UXP is a new technology and is not compatible with older ExtendScripts

 

You must save your code to *.psjs file (UXP script standalone) and run it via File > Scripts > Browse... (drag and drop is not supported yet)

 

you can read more here: UXP Scripting in Photoshop

1 reply

jazz-yCorrect answer
Legend
March 29, 2023

*.jsx are scripts written in ExtendScript, an old scripting engine

UXP is a new technology and is not compatible with older ExtendScripts

 

You must save your code to *.psjs file (UXP script standalone) and run it via File > Scripts > Browse... (drag and drop is not supported yet)

 

you can read more here: UXP Scripting in Photoshop

ze0D45Author
Participant
March 31, 2023

Thank you! This helps so much. I didn't know these differences before, now I can actually focus where I'm looking up scripting references.