skip to Main Content

I am trying to run a jsx script that will load an image, unlock the layer, use the "Remove Background" quick action, and save the image as a PNG. How do you trigger "Remove Background" quick action in scripts?

I have read through Adobe’s JavaScript documentation and don’t see anything about Quick Actions. I also read this post about triggering actions but did not see the "Remove Background" ATN file. I image is would look something like this:

app.doAction("RemoveBackground","RemoveBackground.ATN")

Is running the Remove Background quick action through scripts possible, and if so how do you do it?

2

Answers


  1. You can execute an action with a script by using the following:

    play_action("my action","my action Set");
    
    function play_action(actionName, actionSetName)
    {
        try
        {
            app.doAction(actionName,actionSetName);
        }
        catch(eek)
        {
            alert(eek + "nAction not triggered");
        }
    }
    

    Where "my action",is the name of your action as a string – "remove background" and "my action Set" is the folder/ set in which it is in.

    To remove a background simply search for the layer that has the flag isBackgroundlayer

    // call the source document
    var srcDoc = app.activeDocument;
    var b = srcDoc.layers.length -1;
    
    // search for background layer
    if (srcDoc.layers[b].isBackgroundLayer == true)
    {
      srcDoc.layers[b].remove();
    }
    else
    {
      alert("No background layer found");
    }
    
    Login or Signup to reply.
  2. I know this is an old thread, but I found a solution described on Instructables and hosted at GitHub, which does work. This is not my solution but I have successfully used it.

    The action that you use to remove the background seems to be a compound action in which you select the subject using something labeled "autoCutout" and then invert the selection. I don’t have enough knowledge to tell you anything more, other than that it works.

    Warning: Photoshop did crash while I was using this.

    Links here:

    https://github.com/kavindupasan/batch-bg-remover-photoshop
    https://www.instructables.com/Remove-Background-of-Multiple-Images-Using-Photosh/

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search