I need help. I’m trying to create a batch processing where the function gives me the option to choose the folder, then it opens each photo one by one, applies a specific effect, and saves them in a subfolder.
My problem is: when the images are opened and the effect is applied, they are not being saved in the subfolder.
Could someone please give me some guidance?
async function openImagesOneByOne(folderPath) {
const folder = await fs.getFolder(folderPath);
const files = await folder.getEntries();
// Criar a pasta "Fotos Tratadas"
const treatedFolder = await folder.createFolder("Fotos Tratadas");
for (const file of files) {
if (file.isFile && file.name.match(/\.(jpeg|jpg|gif|png|nef)$/i)) {
try {
let token = fs.createSessionToken(file);
await app.batchPlay([
{"_obj": "open", "documentID": 115, "null": {"_kind": "local", "_path": token}, "template": false}
], {synchronousExecution: false});
await app.batchPlay([
// Aplicar o efeito "Nitidez Suave" na imagem
], {});
// Salvar a imagem na pasta "Fotos Tratadas"
const treatedFile = await treatedFolder.createFile(file.name, {overwrite: true});
const treatedToken = fs.createSessionToken(treatedFile);
await app.batchPlay([
{"_obj": "save", "as": {"_obj": "fileReference", "_path": treatedToken}, "in": {"_path": treatedToken}, "documentID": app.activeDocument.id, "saveStage": 1, "copy": true}
], {synchronousExecution: false});
// Fechar a imagem atual
await app.activeDocument.close();
} catch (err) {
alert(`Erro ao processar a imagem ${file.name}: ${err.message}`);
}
}
}