Greeting everyone!
After longer period of time, I am back with another question. I am trying to get my program to go through files in a directory and open them one by one in Photoshop. I managed to sort out the files properly to open them in the correct order but now I run into another issue. When I try to open the files, I get an error that the action I want to do must be inside modal scope. However, the function is called using executeAsModal which doens’t make sense. See for yourself (openNextFile is the function in question).
async function runModal(command) {
try {
if (command == "start") {
await require('photoshop').core.executeAsModal(selectFile);
} else if (command == "next") {
await require('photoshop').core.executeAsModal(openNextFile(false));
} else if (command == "previous") {
await require('photoshop').core.executeAsModal(openNextFile(true));
} else {
console.log("None of the commands were fulfilled")
}
async function openNextFile(reverse) {
console.log("next file");
let entry;
if (reverse) {
currIndex--;
entry = workFolder.get(Array.from(workFolder.keys())[currIndex]);
} else {
currIndex++;
entry = workFolder.get(Array.from(workFolder.keys())[currIndex]);
}
await openFile(entry);
}
async function openFile(entry) {
try {
const app = require("photoshop").app;
if (entry.isEntry) {
const document = await app.open(entry);
} else {
console.log("the file is not an entry")
}
} catch (e) {
console.log(e);
}
}
If there is need for any more of my code, just let me know. I use manifest v5 btw. Any help is appreciated.