How to create a basic save image UXP script?
I am new to Photoshop UXP scripts. I am trying to create a simple UXP script that will resize the current image in Photoshop and then save it to a user specified file location. So far, I have only written the image save code (i.e., no resize code), but it is not working. Here is the code:
const ps = require('photoshop');
const uxp = require('uxp');
const fs = uxp.storage.localFileSystem;
const core = ps.core;
const app = ps.app;
const img = app.activeDocument;
try {
const file = await fs.getFileForSaving('', { types: [ 'jpg' ] });
img.saveAs.jpg(file, { quality: 8 });
} catch (e) {
core.showAlert(e.message);
console.log(e);
}
I think the code is throwing on img.saveAs after I click the Save button on the Save dialog. However, I cannot get the PS debugger connected to the script, so I have no logs. Curiously, core.showAlert in the catch clause does not display an alert, so I'm completely blind. I can display an alert before the call to img.saveAs, but not immediately after that line., so it must be either throwing or completely crashing when I click the Save button.
A small dialog appears on the screen after I click the Save dialog's Save button. The dialog disappears in a flash (I can't even capture it with a screen recorder), but it looks like it might be a progress bar. The image file is not saved.
It's very frustrating to have no way to debug the problem, but it is what it is. Can anyone see what is wrong, or have any suggestions?
