Skip to main content
Known Participant
August 13, 2023
Question

How to pass arguments from Javascript file into .jsx file, in a Photoshop plugin?

  • August 13, 2023
  • 0 replies
  • 338 views

This code from my main.js file works to effectively run the .jsx script -- however I can't for the life of me figure out how to pass arguments/user-defined variables into this .jsx file for use in there. Any ideas?

async function executeScript() {
    const filePath = document.querySelector("#filePath").value;
    const savePath = document.querySelector("#savePath").value;
    const imageFolder = document.querySelector("#imageFolder").value;

    if (!filePath || !savePath || !imageFolder) {
        alert("Please fill in all the fields before proceeding.");
        return;
    }

    try {
        console.log("MADE IT HERE");

        const pluginFolder = await fs.getPluginFolder();
        const scriptFile = await pluginFolder.getEntry(batchReplacePath);
        var filetoken = await fs.createSessionToken(scriptFile);

        const result = await photoshop.action.batchPlay(
            [
                {
                    "_obj": "AdobeScriptAutomation Scripts",
                    "javaScript": {
                        "_path": filetoken,
                        "_kind": "local"
                     },
                    "javaScriptArgs": {
                        "_obj": "javaScriptArgs",
                        "PhotoshopFilepathToUse": filePath,
                        "ImageFolderToUse": imageFolder,
                        "OutputPath": savePath,
                        "imageType": "JPEG",  // Hardcoding for this example
                        "imageQuality": 8     // Hardcoding for this example
                    }
                }
               
            ],
            {
                "synchronousExecution": false,
                "modalBehavior": "fail"
            }
        );
        console.log(result);

        if (result && result[0] && result[0].status === "OK") {
            alert("Batch replacement completed successfully.");
        } else {
            alert("An error occurred during the process.");
        }
    } catch (error) {
        alert("Error: " + error);
    }
}

When I try to access or alert the passed in arguments/variables, they all show up as undefined. What am I doing wrong? What is the correct way to do this?

Thanks!
This topic has been closed for replies.