I have tried the code from Save File with user defined Native path but it never saves the file.
Here is the full code I have.
API-2 and Manifest 5
I have 2 buttons, one asks the user to set a location and the other button saves the file.
//Button to open Dialog asking where to save to
document.getElementById('chooseLocation').addEventListener('click', async () => {
await exeModal(doStuff, {
"commandName": "Please Wait"
});
async function doStuff(executionContext) {
let hostControl = executionContext.hostControl;
// Get an ID for a target document
let documentID = await app.activeDocument._id;
// Suspend history state on the target document
let suspensionID = await hostControl.suspendHistory({
"historyStateInfo": {
"name": "Your History State Name",
"target": [{
_ref: "document",
_id: documentID
}]
}
});
/*
Do stuff here.
It can be batchPlay or any other javascript code
*/
var myFolder = await require("uxp").storage.localFileSystem.getFolder();
let token = await require("uxp").storage.localFileSystem.createPersistentToken(myFolder);
localStorage.setItem("persistent-token", token);
await hostControl.resumeHistory(suspensionID);
}
});
// Button to save the file
document.getElementById('saveFile').addEventListener('click', async () => {
await exeModal(doStuff, {
"commandName": "Please Wait"
});
async function doStuff(executionContext) {
let hostControl = executionContext.hostControl;
// Get an ID for a target document
let documentID = await app.activeDocument._id;
// Suspend history state on the target document
let suspensionID = await hostControl.suspendHistory({
"historyStateInfo": {
"name": "Your History State Name",
"target": [{
_ref: "document",
_id: documentID
}]
}
});
/*
Do stuff here.
It can be batchPlay or any other javascript code
*/
const entry = await require("uxp").storage.localFileSystem.getEntryForPersistentToken(localStorage.getItem("persistent-token"));
const newFile = await entry.createFile(app.activeDocument.name, {
overwrite: true
});
const saveFile = await require("uxp").storage.localFileSystem.createSessionToken(newFile);
await hostControl.resumeHistory(suspensionID);
}
});