Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Run Quick Action via script/plugin

Explorer ,
Apr 01, 2025 Apr 01, 2025

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(":white_heavy_check_mark: Background removed successfully!");
} catch (error) {
console.error(":cross_mark: Error removing background:", error);
displayMessage("Failed to remove background: " + (error.message || "Unknown error"));
}
});

TOPICS
Actions and scripting , SDK , Windows
86
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Enthusiast , Apr 02, 2025 Apr 02, 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

...
Translate
Adobe
Enthusiast ,
Apr 02, 2025 Apr 02, 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 02, 2025 Apr 02, 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 😕 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Apr 02, 2025 Apr 02, 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 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 02, 2025 Apr 02, 2025
LATEST

It works! Thansk! 🫶

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines