Photoshop jsx 脚本 - 脚本工作正常,但我希望能够在没有对话和选择的情况下使用它

Photoshop jsx script - script works fine but I want to be able to use it without a dialogue and selection

我有一个脚本正在一个更大的项目中使用

在 Photoshop 中我有一个名为 images 的组和一个图层在里面

我已经设法使该脚本正常工作。一个对话框打开我 select 文件并且它毫无问题地替换了内容

但我希望脚本 运行 无需打开对话并且必须 select 文件

我要替换的文件名为london.png

如何在没有对话的情况下自动执行此操作

这是我的代码以及它所要求内容的屏幕截图(我想消失并自动 select london.png

还有根文件夹和文件的截图

    var replacementFile = new File("~/london.png");
    var theLayer = app.activeDocument.layerSets.getByName('image');
    var changeLayer = theLayer.layers[0]
    changeLayer = replaceContents(replacementFile);

    ////// replace contents //////  
    function replaceContents (newFile) {  
    // =======================================================  
    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 );  
    return app.activeDocument.activeLayer  
    };  

截图1对话

截图2文件结构

///// >>> the mistake was here
var replacementFile = new File("C;/users/harry/script/london.png");
var theLayer = app.activeDocument.layerSets.getByName('image');
var changeLayer = theLayer.layers[0]
changeLayer = replaceContents(replacementFile);

////// replace contents //////  
function replaceContents (newFile) {  
// =======================================================  
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 );  
return app.activeDocument.activeLayer  
};