Alchemist help needed

Hi everyone,
I have problems making functions from code generated by Alchemist. +/- 90% of the time “IT DOESN’T WORK” :hot_face:
So what is wrong with the following or more probably what did I do wrong:

Top of index.js
var batchPlay = require(“photoshop”).action.batchPlay;
const app = require(‘photoshop’).app;
const docPath = app.activeDocument.path;

The function:
var saveTIF = async () => {
//async function saveTIF () {
await batchPlay(
[
{
“_obj”: “save”,
“as”: {
“_obj”: “TIFF”,
“byteOrder”: {
“_enum”: “platform”,
“_value”: “IBMPC”
}
},
“in”: {
“_path”: “D:\\Entrepot\\LR-PE\\UXP\\Tools3\\Panel.tif”,
“_kind”: “local”
},
“documentID”: 654,
“lowerCase”: true,
“saveStage”: {
“_enum”: “saveStageType”,
“_value”: “saveBegin”
},
“_isCommand”: false,
“_options”: {
“dialogOptions”: “dontDisplay”
}
}
],{
“synchronousExecution”: false,
“modalBehavior”: “fail”
});
}

One obvious issue is that you have to use tokens instead of paths when saving files using UXP. Do a search for “token” in this forum and you’ll see several posts that address this issue.

Thanks, I will search the forum.

Yes I didn’t implement support for

  • file-path data type (this could be possible to do but it is not that easy)
  • raw data type (there is no information on whether this data type is implemented or how to use it so I don’t know what to generate) Adobe: please tell us how to deal with it.

Thanks for the information. If it was the only thing that I can not implement from Alchemist listing, that would only be an inconvenient. I can not implement simple things like tools.
I have over 200 buttons, 4 sliders & 125 jsx files for this panel. If I can not port these I will have to use Photoshop 2021 to have access to my 4 panels. There must be something I am doing wrong or not doing.
Well, back to work and thanks again.

Problem solved at 90% for saving an open document at the touch of a button:
Get folder key, Create file, Get file key and Save the document format tif

The purpose behind my panel is to save clicks or click a button and the job is done.
So how to eliminate the need to re-select the folder?

// Save open document as tif
const zz = async () => {
var doc = app.activeDocument;
const docPath = app.activeDocument.path;
var fin = docPath.length - docPath.lastIndexOf("\") - 1 - 4;
var debut = docPath.lastIndexOf("\")+1
const docName = docPath.substr(debut, fin);
const pathNoExt = docPath.substr(0, docPath.length-4);
const docPathShort = docPath.substr(0, docPath.lastIndexOf("\"));

// Get folder key
var saveFolder = await require(“uxp”).storage.localFileSystem.getFolder(docPathShort);
// Create file
var saveFile = await saveFolder.createFile(docName+".tif");
// get file key
var saveFileToken = await require(“uxp”).storage.localFileSystem.createSessionToken(saveFile);

// Save the flie why re-select the folder
await saveTIF(saveFileToken);

async function saveTIF(fileToken){

const batchPlay = require(“photoshop”).action.batchPlay;

await batchPlay(
[
{
“_obj”: “save”,
“as”: {
“_obj”: “TIFF”,
“byteOrder”: {
“_enum”: “platform”,
“_value”: “IBMPC”
},
“LZWCompression”: true,
“saveTransparency”: true,
“layerCompression”: {
“_enum”: “encoding”,
“_value”: “RLE”
}
},
“in”: {
“_path”: fileToken,
“_kind”: “local”
},
“saveStage”: {
“_enum”: “saveStageType”,
“_value”: “saveBegin”
},
“_isCommand”: false,
“_options”: {
“dialogOptions”: “dontDisplay”
}
}
],{
“synchronousExecution”: false,
“modalBehavior”: “fail”
});
}
}

Instead of a session token you can create, save and load a persistent token.

Seems to be documented only for XD but works also for Photoshop:

Thanks, I will try it right now

It’s doc’d here for PS: https://www.adobe.io/photoshop/uxp/uxp/reference-js/Modules/uxp/Persistent%20File%20Storage/FileSystemProvider/#createpersistenttokenentry

Thanks Kerri. Then it seems the search function is not working properly. I searched for createPersistentToken and it gave me no results.

Yeah; the search is not good right now. We’re hoping that we can improve it soon.