Copy link to clipboard
Copied
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"));
}
});
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
...Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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 😕
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
It works! Thansk! 🫶