Can save from panel, can't from dialog

Using both saveAs or Batchplay to save both a JPG or PNG works from a panel. Using the same code but from a dialog doesn’t seem to actually create the file for saving. Both use getpluginFolder().

Is there something needed to allow a dialog to save?

Example code:

 const dataFolderToSaveFileTo = await fs.getPluginFolder();
        //create the file with combined name and path
        const holdNewFile = await dataFolderToSaveFileTo.createFile(`${passedFileName}.png`, { overwrite: true });
        await core.executeAsModal(async () => {
            try {
                const activeDocument = require("photoshop").app.activeDocument;
                await activeDocument.saveAs.png(holdNewFile, true);
            }

Are you refering to .psjs script? Or dialog within a plugin with manifest?

Jarda,

Plugin with manifest.

  "entrypoints": [
    {
      "type": "command",
      "id": "myDialogThatSaves",
      "label": "mylabeloftext"
    },

Html

  <dialog id="myDialogThatSaves" style="padding: 10px;overflow-y: hidden;" width="600px" height="520px" title="Save your file">
  </dialog>
</body>

Ah, ok. What holdNewFile says when you ask for native path?

It correctly shows the plugin folder, so it does seem to manage to use the filestorage.

this is just a guess.
but I suspect its because of the modal state if present

Photoshop allows one modal state and if the dialog is shown as modal PS might refuse to execute your code.

this should produce an error message I think.
try wrapping the whole executeasmodal call in a try/catch just to make sure

1 Like

Maher,

Already wrapped in a try/catch - catch never fired, no errors in the console. After this save, I upload the file we’ve just created (temporary file so we can upload it).

async function savePNGFileBatchPlay(saveFile, passedFileName) {
    try {
        const dataFolderToSaveFileTo = await fs.getPluginFolder();
        //create the file with combined name and path
        const holdNewFile = await dataFolderToSaveFileTo.createFile(`${passedFileName}.png`, { overwrite: true });
        await core.executeAsModal(async () => {
            try {
                const activeDocument = require("photoshop").app.activeDocument;
                await activeDocument.saveAs.png(holdNewFile, true);
            }
            catch (errorMsg) {
                console.log("Error inside modal: " + errorMsg);
            }
        }, { "commandName": `Saving temp file ${passedFileName}.${chosenFormat}......` });;
    }
    catch (errorMsg) {
        console.log(errorMsg);
    }
    return;
}

The file is found from the system by:

                const folder = await fs.getPluginFolder();
                const entries = (await folder.getEntries());
                var fileNameToFind = `${enteredFileName}.${chosenFormat}`;
                myTempFile = entries.find(a => a.name.includes(fileNameToFind));

                if (!myTempFile) {
                    console.log(`Error finding file in pluginFolder - ${fileNameToFind}`);
                    console.log(`Could not find ${fileNameToFind} in path ${folder.nativePath} `);
                    await error("Upload error",
                        "Temp file was not created successfully.");
                }

It enters this false if check, due to myTempFile not being found. This code works however when it is a panel.

Did you have an opportunity to play with interactive mode? https://developer.adobe.com/photoshop/uxp/2022/ps_reference/media/executeasmodal/#interactive-mode

Here is a primitive solution, As it is stated above photoshop allow only one modal state each time, I had this same issue, from dialogue I wanted to open the PS preferences, how I solved I added a

close()

Before running the code that will open PS preferences, you can add another Open dialogue at the end if you need to open the dialogue again. Primitive, but worked for me.

2 Likes

Same issue regardless of setting interactiveMode to true or false. File is never created to disk it seems. ‘holdNewFile’ does have the nativePath set correctly to where I’m trying to temporarily store it.

    try {
        const dataFolderToSaveFileTo = await fs.getPluginFolder();
        //create the file with combined name and path
        const holdNewFile = await dataFolderToSaveFileTo.createFile(`${passedFileName}.png`, { overwrite: true });
        await core.executeAsModal(async () => {
            try {
                const activeDocument = require("photoshop").app.activeDocument;
                await activeDocument.saveAs.png(holdNewFile, true);
            }
            catch (errorMsg) {
                console.log("Error inside modal: " + errorMsg);
            }
        }, {
            "commandName": `Saving temp file ${passedFileName}.${chosenExportFormat}......`,
            "interactive": false
        });;
    }
    catch (errorMsg) {
        console.log(errorMsg);
    }
    return;

Wanokuni

Thank you for this idea. This has allowed me to save the file. Issue now is that the dialog closes and until my task is finished server side, I don’t display the ‘upload successful’ message. I feel the user may wonder what’s going on.

For some reason, executeAsModal isn’t showing the progress bar I previously had. However, there seems to be issue somehow that it doesn’t always show up anyway (longer than 2 second task, so it should be).

Ignore that - embarrassingly, the dialog was showing on the second monitor… it’s been a long day of work :smiley:

1 Like

Great, it worked for you. You can handle it how you see fit, for example when upland is done show an alert to let users know, or reopen your first dialogue again.

1 Like

I remember forcing the progress bar to show by providing a commandName and setting prgress.

however it still sometimes does not show I don’t know why

1 Like

Gone with showing successful message and not showing it again. My use case doesn’t make sense to exporting it again immediately anyway. Thank you for your help.

A dialog is intended to ask a question. For example, Export As asks what (limited) alterations would you like before saving a copy. The file dialog that will appear asks what name (and path). Upon supplying those answers, the user clicks the “action” button, say Export or Save. The dialog closes, and then the action is taken.