Thanks again for the reply. So, I have been able to successfully create a plugin that generates a token by
invoking a dialog and having the user select an image file. Then the user can create/directly import that image file (without the dialog being invoked) by setting the path = to the Token in the Place command.
This all works great. Code I’m using is below.
But here is the issue:
When I look in the console for the output of the console.log for //STORED FILE NAME (see below)
it appears to be identical to the output for the console.log for //DIALOG FILE NAME (see below)
So I at first thought I could dispense with filename = await fs.getFileForOpening(); (to avoid the dialog)
and instead just set filename = to a hard coded string that was identical to the string that was shown in the console for the filename value returned by fs.getFileForOpening();
However, the code does not work (despite no error message/no message at all in the debug screen)
I’m assuming this has to do with the fact that fs.getFileForOpening() returns a Type of File
and not a Type of String?
Any suggestions as to how to use the hard coded filename to make it work like the filename that is returned by fs.getFileForOpening(); ?
Thanks!
CODE***************
const fs = require(“uxp”).storage.localFileSystem;
let entry;
async function getToken() {
const filePath = String.rawC:\\g.png
;
var filename = ‘{“name”:“g.png”,“type”:“file”,“nativePath”:"’ + filePath +‘"}’;
console.log("stored filename " + filename); //STORED FILE NAME
filename = await fs.getFileForOpening();
console.log("dialog filename " + filename); //DIALOG FILE NAME
let token = await fs.createPersistentToken(filename);
console.log("token " + token);
document.getElementById(“myfile”).value = filename.name;
document.getElementById(“tok”).value = token;
localStorage.setItem(“persistent-file”, token);
entry = await fs.getEntryForPersistentToken(token);
console.log("entry " + entry);
}
async function imagePlacer()
{
const myToken = await fs.createSessionToken(entry);
console.log("myToken " + myToken);
let result;
let psAction = require(“photoshop”).action;
let command = [
// Place
{“ID”:3,“_obj”:“placeEvent”,“freeTransformCenterState”:{“_enum”:“quadCenterState”,“_value”:“QCSAverage”},“null”:{“_kind”:“local”,“_path”:myToken},“offset”:{“_obj”:“offset”,“horizontal”:{“_unit”:“pixelsUnit”,“_value”:0.0},“vertical”:{“_unit”:“pixelsUnit”,“_value”:0.0}},“replaceLayer”:{“_obj”:“placeEvent”,“from”:{“_id”:2,“_ref”:“layer”},“to”:{“_id”:3,“_ref”:“layer”}}}
];
result = await psAction.batchPlay(command, {});
}
async function newtest()
{
await require(“photoshop”).core.executeAsModal(imagePlacer, {“commandName”: “Action Commands”});
}
document.getElementById(“btnGetToken”).addEventListener(“click”, getToken);
document.getElementById(“btnImportImage”).addEventListener(“click”, newtest);