Hi
I’m creating a plugin that has to open, save and close a lot of smart objects, which takes a considerable amount of time when using the DOM.
As a result, I was trying to find a way to do it through batchplay, but I’m not sure how to ask the user for access to the AppData folder?
So far I managed to get the path to the temp folder, the name of each smart object, and I think I pretty much understand how to get a token to be used in batchplay. But I’m struggling with figuring out a way to get access to the temp folder.
Unless I’m doing something wrong, the domains that might be relevant aren’t supported. According to the fs.supportedDomains method, the only domains I can access are userDesktop, userDocuments and userPictures.
I also tried using the plugin’s temporary folder, but my code doesn’t seem to work. It saves the same smart object over and over again, and then closes both the smart object’s document and the document it was opened through.
async function SaveCloseDoc() {
const doc = await batchPlay(
[
{
"_obj": "get",
"_target": [
{
"_ref": "document",
"_enum": "ordinal",
"_value": "targetEnum"
}
],
"_options": {
"dialogOptions": "dontDisplay"
}
}
], {
"synchronousExecution": false,
"modalBehavior": "fail"
});
const fileTitle = doc[0].title;
const docID = doc[0].documentID;
const fileSystem = await require("uxp").storage.localFileSystem;
const tempFolder = await fileSystem.getTemporaryFolder();
const newFile = await tempFolder.createFile(fileTitle, { overwrite: true });
const fileToken = await fileSystem.createSessionToken(newFile);
await batchPlay(
[
{
"_obj": "save",
"in": {
"_path": fileToken,
"_kind": "local"
},
"saveStage": {
"_enum": "saveStageType",
"_value": "saveBegin"
},
"documentID": docID,
"_isCommand": true,
"_options": {
"dialogOptions": "dontDisplay"
}
},
{
"_obj": "close",
"documentID": docID,
"forceNotify": true,
"_isCommand": true,
"_options": {
"dialogOptions": "dontDisplay"
}
}
], {
"synchronousExecution": false,
"modalBehavior": "fail"
});
}
What am I missing…? Is there a better way to go about saving a smart object?
Also, is there a way to ask the user to grant permission without opening the file picker, so they won’t be able to pick a different folder?
Thank you!