I have a piece of script which I am using in a bigger project
In Photoshop I have a group named images and a layer inside
I have managed to get this script working. A dialogue opens I select the file and it replace the content without problem
But I want the script to run without opening a dialogue and having to select a file
The file I want to replace is called london.png
How do I do this automatically without a dialogue
Here’s my code and also a screenshot of what it asks (dilog I want to disappear and auto select london.png
Also a screenshot of the root folder and files
JavaScript
x
18
18
1
var replacementFile = new File("~/london.png");
2
var theLayer = app.activeDocument.layerSets.getByName('image');
3
var changeLayer = theLayer.layers[0]
4
changeLayer = replaceContents(replacementFile);
5
6
////// replace contents //////
7
function replaceContents (newFile) {
8
// =======================================================
9
var idplacedLayerReplaceContents = stringIDToTypeID( "placedLayerReplaceContents" );
10
var desc3 = new ActionDescriptor();
11
var idnull = charIDToTypeID( "null" );
12
desc3.putPath( idnull, new File( newFile ) );
13
var idPgNm = charIDToTypeID( "PgNm" );
14
desc3.putInteger( idPgNm, 1 );
15
executeAction( idplacedLayerReplaceContents, desc3, DialogModes.NO );
16
return app.activeDocument.activeLayer
17
};
18
Screenshot 1 dialogue
Screenshot 2 file structure
Advertisement
Answer
JavaScript
1
19
19
1
///// >>> the mistake was here
2
var replacementFile = new File("C;/users/harry/script/london.png");
3
var theLayer = app.activeDocument.layerSets.getByName('image');
4
var changeLayer = theLayer.layers[0]
5
changeLayer = replaceContents(replacementFile);
6
7
////// replace contents //////
8
function replaceContents (newFile) {
9
// =======================================================
10
var idplacedLayerReplaceContents = stringIDToTypeID( "placedLayerReplaceContents" );
11
var desc3 = new ActionDescriptor();
12
var idnull = charIDToTypeID( "null" );
13
desc3.putPath( idnull, new File( newFile ) );
14
var idPgNm = charIDToTypeID( "PgNm" );
15
desc3.putInteger( idPgNm, 1 );
16
executeAction( idplacedLayerReplaceContents, desc3, DialogModes.NO );
17
return app.activeDocument.activeLayer
18
};
19