Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

How to Script Adding An Empty, White Layer + Merging X Number of Layers into normal Raster layer

New Here ,
Apr 24, 2019 Apr 24, 2019

Hello! I'm hoping for some pointers on how I could go about scripting the following for a Photoshop file: a) merging x number of layers into a normal raster layer and then b) adding a new, white background only layer to that file.

The background is that my company's creative team has thousands of files which we must now standardize to only have two layers - one which is a blank background layer and the other which is a merged layer of all of our product SKUs. This is to give our design team (which is a separate team) a consistent starting point when dealing and editing our (the creative team's) PSD files.

Obviously, since there are thousands of files, we'd rather not go through and update each PSD file one by one. Is there a way to automate this?

The ideal solution would not require me or my team to open up the Photoshop app to execute these actions. Ideally, this could be scripted from the command line referencing a Photoshop executable or SDK (if there is such a thing?).

Please let me know if I can provide additional context to address the above question. And thanks in advance for any help!

TOPICS
Actions and scripting
419
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe
Community Expert ,
Apr 24, 2019 Apr 24, 2019

// 2019, use it at your own risk;

#target photoshop

if (app.documents.length > 0) {

var myDoc = app.activeDocument;

myDoc.activeLayer = myDoc.backgroundLayer;

var aLayer = myDoc.artLayers.add();

aLayer.name = myDoc.name;

try {myDoc.backgroundLayer.remove()} catch (e) {};

try {myDoc.mergeVisibleLayers()} catch (e) {};

deleteHiddenLayers ();

resetForeAndBackground();

var anotherLayer = myDoc.artLayers.add();

anotherLayer.isBackgroundLayer = true

};

////// delete hidden layers //////

function deleteHiddenLayers () {

try {

// =======================================================

var desc3 = new ActionDescriptor();

var ref2 = new ActionReference();

ref2.putEnumerated( charIDToTypeID( "Lyr " ), charIDToTypeID( "Ordn" ), stringIDToTypeID( "hidden" ) );

desc3.putReference( charIDToTypeID( "null" ), ref2 );

executeAction( charIDToTypeID( "Dlt " ), desc3, DialogModes.NO );

} catch (e) {}

};

////// reset fore- and background color //////

function resetForeAndBackground () {

// =======================================================

var desc2 = new ActionDescriptor();

var ref1 = new ActionReference();

ref1.putProperty( charIDToTypeID( "Clr " ), charIDToTypeID( "Clrs" ) );

desc2.putReference( charIDToTypeID( "null" ), ref1 );

executeAction( charIDToTypeID( "Rset" ), desc2, DialogModes.NO );

};

Edit:

If you want to give it a try, save the above text as a new txt-file with the extension jsx into Photoshop’s Presets/Scripts-folder.

After restarting Photoshop the Script should be available under File > Scripts and can be assigned a Keyboard Shortcut directly and recorded into an Action.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 27, 2019 Apr 27, 2019

Thanks! This is very helpful. Would there be a way to run this on a remote server? Or does this script always need to be run within the Photoshop application?

(Perhaps a very naive / simple question but please bear with me as I am very much a Photoshop novice.)

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 28, 2019 Apr 28, 2019
LATEST
does this script always need to be run within the Photoshop application?

Yes.

Other applications might offer other options, though.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines