How to invoke main plugin command twice when the plugin button is pressed once

I want to invoke the main plugin function command twice when the user clicks the button or uses it’s shortcut.
How can I achieve that

May I ask what’s the use-case here? I might misunderstand you (if so, please tell me), but why can’t you just do a simple loop to run the code twice (see below)?

function main(selection) {
  for (let i = 0; i < 2; i++) {
    // Your code here

module.exports = {[...]}


The use case is if I run my plugin two times continuously I’m able to get my desired output.
But, If I run my plugin only once the output is different or maybe not expected.

So, my requirement is whenever the user runs my plugin for once it should be invoked twice(The whole java script should be executed twice). Any help?

Then, my question why you can’t simply use a for loop (see my answer above) for that stays :wink:

1 Like

Sounds more like there’s a bug going on that causes the plugin to return incorrect results the first time it is run. Rather than executing things twice, I would concentrate on finding the underlying issue.

Sharing some code snippets might help :slight_smile:


In my code in main function I have three sections as follows:

  1. Getting the temporary folder and rendering a image file into the temporary folder.

  2. After creating trying to fill the file in the selection.items[0].
    3.After filling trying to delete the temporary file which is created in the first step.

But the thing is when I run the code into for the first time it says:

Plugin Error: Cannot load ImageFill from path: C:\Users\rajasekhar.b\AppData\Local\Packages\Adobe.CC.XD_adky2gkssdxte\TempState\UXP\PluginsTemp\External\d94b0698\compressed.jpg
at new ImageFill (plugins/BitmapFillWrapper.js:1:514)
at myPluginCommand (C:\Users\rajasekhar.b\AppData\Local\Packages\Adobe.CC.XD_adky2gkssdxte\LocalState\develop\Compress Now\main.js:67:28)

For the 2nd time when I run that:
It’s filling the image file into the selection and deleting the temporary file.

I tried. But, it won’t work:neutral_face:

The main thing is instead of creating temp file first. The plugin runs the imagefill command.
Not executing in order

Are you awaiting (the Promise of) the creation of the image? It kind of sounds to me like you’re not awaiting this asynchronous creation and it’s finished when you run it the second time…

1 Like

How to await the asynchronous creation?

The File IO APIs are asynchronous and use the (standard) JavaScript Promise APIs. You can read more about the asynchronous part at If you don’t know Promises yet, just google for JavaScript Promises and you’ll find many articles explaining it.

Hope this helps,

Could you possibly create a Gist on GitHub or some other platform where I can easily refer to line numbers etc.? Then, I’ll be happy to do a quick review of your code (like this, I’d need to refer to things like “where you write …”, which is a bit imprecise and cumbersome :wink:).

Thank you very much in advance :+1:

Perfect, thank you. As far as I can see it, you can simply replace

            .then(results => {
                // // create the dialog
                // let dialog = document.createElement("dialog");

                // // main container
                // let container = document.createElement("div");
                // = 400;
                // = 60;

                // // add conten
                // let title = document.createElement("h2");
                // = 20;
                // title.textContent = `Compress Now worked!`;
                // container.appendChild(title);

                // // close button
                // let closeButton = document.createElement("button");
                // closeButton.textContent = "Got it!";
                // = 20;
                // container.appendChild(closeButton);
                // closeButton.onclick = (e) => {
                //     dialog.close();
                // }

                // document.body.appendChild(dialog);
                // dialog.appendChild(container);
                // dialog.showModal()
                console.log("Image Created");
            .catch(error => {


await application.createRenditions(renditions);

in the main.js file (lines 27-60) of the a-way-to-fix-bug-branch, and it should do the trick. I don’t have much time right now, so if this doesn’t work, there isn’t much I can do to help you at this point in time, but I think it should at least get you one step closer to getting it to work (it isn’t my task to fix all potential issues, but only this one, after all :wink:)

1 Like

Thanks alot!
Maybe now I can fix that

1 Like