I modified a script. Original version of a script is like https://gist.github.com/laryn/0a1f6bf0dab5b713395a835f9bfa805c. Issue is I am providing the artwork as an argument to my modified script so that it gets replaced in smart object directly without prompting for selecting an artwork. Someday's ago this script was working file and not asking me for selection but now it does..any idea...anyone plese help...I turned even default Dilogmodes to No !

var artName = File(arguments[0]);
var theLayer;
var curLayer;
var myDocument;

app.displayDialogs = DialogModes.NO


function main(artName)
     if (app.documents.length > 0)
        var myDocument = app.activeDocument;
        var theName = myDocument.name.match(/(.*)\.[^\.]+$/)[1];
        var thePath = myDocument.path;
        goThroughLayers (myDocument);
        // PSD Options;
        psdOpts = new PhotoshopSaveOptions();
        psdOpts.embedColorProfile = true;
        psdOpts.alphaChannels = true;
        psdOpts.layers = true;
        psdOpts.spotColors = true;
        if (theLayer.kind != "LayerKind.SMARTOBJECT") {
            alert("selected layer is not a smart object")
                    // Replace SmartObject
                    var theNewName = artName.name.match(/[^\\]*(?=\.[^.]+$)/)[0];
                    replaceContents(artName, theLayer);
                    myDocument.saveAs((new File(thePath + "/" + theName + "_" + theNewName + "_mu_.psd")), psdOpts, true);

function replaceContents(newFile, theSO)
    app.activeDocument.activeLayer = theSO;
        var idplacedLayerReplaceContents = stringIDToTypeID("placedLayerReplaceContents");
        var desc3 = new ActionDescriptor();
        var idnull = charIDToTypeID("null");
        desc3.putPath(idnull, new File(newFile));
        var idPgNm = charIDToTypeID("PgNm");
        desc3.putInteger(idPgNm, 1);
        executeAction(idplacedLayerReplaceContents, desc3, DialogModes.NO);
    catch (e) 
        return app.activeDocument.activeLayer;

function goThroughLayers(parentLayer)
    for(var i=0;i<parentLayer.layers.length;i++){
        curLayer = parentLayer.layers[i];

                app.activeDocument.activeLayer = curLayer;
        if(curLayer.typename =="LayerSet")
            goThroughLayers (curLayer)
                if(curLayer.name=='PLACE YOUR LOGO'|| curLayer.kind == "LayerKind.SMARTOBJECT")
                            theLayer = curLayer;
                }//end else
            }//end loop
    }//end function

function selectChannel (colour){
    var desc = new ActionDescriptor();
    var ref = new ActionReference();
    ref.putEnumerated( charIDToTypeID('Chnl'), charIDToTypeID('Chnl'), stringIDToTypeID(colour) );
    desc.putReference( charIDToTypeID('null'), ref );
    executeAction( charIDToTypeID('slct'), desc, DialogModes.NO );
  • "Someday's ago this script was working file and not asking me for selection but now it does" -- did you accidentally tick the user interaction icon in the Action panel?
    – Scott
    Feb 11 at 20:34
  • May be because I was fiddling around. But I do not know how to turn it off. A screen shot would be a great help. But one thing is if i provide artwork in code like say...var artName = File("D://T Shirt//Technology//WebSite//ArtWork//Bohmanian//401_art.png"); it replaces without asking. I am passing artwork as an argument and then it is prompting dialog. Feb 12 at 1:38

1 Answer 1


Oh....no...my bad.....I changed the path of artwork by moving it to another directory and hence as fail safe, the script is asking for me a replacement artwork....Solved...@Scott thanks for your attention to my question. Appriciate. Anyways, hope this script is payback to community if someone is looking to replace artwork object directly from VB or VBA.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.