For some reason I still can’t wrap my head around the save/token system in UXP
I’ve got a function that saves 2 different files in a folder. At the moment I’m only able to get the function to run if it chooses the folder to save the file every time.
Is there a way to select the save folder on the first file, and then keep it as the save folder for the next one so the user is not alerted/cant change it?
It runs over 30+ files so for the user to click save 30 times is tedious
Current Function Below
document.querySelector("Btn01").onclick = () => {
makeWebFiles();
}
async function makeWebFiles() {
const batchPlay = require("photoshop").action.batchPlay;
const fs = require("uxp").storage.localFileSystem;
const pluginFolder = await fs.getPluginFolder();
const doc1 = await pluginFolder.getEntry("doc1.tif");
const doc2 = await pluginFolder.getEntry("doc2.tif");
await app.open(doc1);
await saveWeb("doc1.jpg");
await app.open(doc2);
await saveWeb("doc2.jpg");
async function saveWeb(saveFileName) {
const persistentFolder = await fs.getFolder();
const newFile = await persistentFolder.createFile(saveFileName, { overwrite: true });
const saveFile = await fs.createSessionToken(newFile);
const result = await batchPlay(
[
{
"_obj": "save",
"as": {
"_obj": "JPEG",
"extendedQuality": 8,
"matteColor": {
"_enum": "matteColor",
"_value": "none"
}
},
"in": {
"_path": saveFile,
"_kind": "local"
},
"copy": true,
"lowerCase": true,
"saveStage": {
"_enum": "saveStageType",
"_value": "saveBegin"
},
},
{
"_obj": "close",
"saving": {
"_enum": "yesNo",
"_value": "no"
},
}
], {
"synchronousExecution": false,
"modalBehavior": "fail"
});
}
}