Skip to main content
Known Participant
April 2, 2025
Answered

Run Quick Action via script/plugin

  • April 2, 2025
  • 1 reply
  • 516 views

I want to make a plugin with a button that triggers a quick action “remove background”, ChatGPT spits me this code, but it does not work. 

document.getElementById("remove-bg-btn").addEventListener("click", async () => {
try {
await executeAsModal(async () => {
await batchPlay([
{
"_obj": "invokeCommand",
"commandID": 3315,
"_isCommand": true
}
], {});
});
console.log("✅ Background removed successfully!");
} catch (error) {
console.error("❌ Error removing background:", error);
displayMessage("Failed to remove background: " + (error.message || "Unknown error"));
}
});

Correct answer Ciccillotto

This is what you are looking for uxp

 

async function remove_background_ok() {
    let result;
    let psAction = require("photoshop").action;

    let command = [
        {"_obj":"removeBackground"}

    
     
    ];
    result = await psAction.batchPlay(command, {});
}

async function remove_background() {
    await require("photoshop").core.executeAsModal(remove_background_ok, {"commandName": "Action Commands"});
}

await remove_background();

here you can download the .psjs file

https://www.mediafire.com/file/coez0mdh6742nc6/Remove_Background2.psjs.zip/file 

1 reply

Inspiring
April 2, 2025

What do you mean by plugin, UXP, javascript, cep? Have you thought about using scriptlistener, or creating an action and then converting it. Let me know what you need and I'll be happy to help.

Known Participant
April 2, 2025

Im creating plugin for file browsing (you can select folder, listing images with lazyload, doubleclick on image adding image to project, simple functions) and its works as I want. I want allso add one button "Background remove", and when I press this button I want run Quick Action (Discovery panel) Remove background. Im trying different things and I cant make it works 😕😕 

CiccillottoCorrect answer
Inspiring
April 2, 2025

This is what you are looking for uxp

 

async function remove_background_ok() {
    let result;
    let psAction = require("photoshop").action;

    let command = [
        {"_obj":"removeBackground"}

    
     
    ];
    result = await psAction.batchPlay(command, {});
}

async function remove_background() {
    await require("photoshop").core.executeAsModal(remove_background_ok, {"commandName": "Action Commands"});
}

await remove_background();

here you can download the .psjs file

https://www.mediafire.com/file/coez0mdh6742nc6/Remove_Background2.psjs.zip/file