Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joonaspaakko/ace1ec3455b6959dc611 to your computer and use it in GitHub Desktop.
Save joonaspaakko/ace1ec3455b6959dc611 to your computer and use it in GitHub Desktop.
// https://gist.github.com/joonaspaakko/ace1ec3455b6959dc611
#target photoshop
// If there are any documents open, run the code...
// =================================================
if ( app.documents.length > 0 ) {
// Used later on when the layers are duplicated back to the original document.
// ===========================================================================
var docName = app.activeDocument.name;
// Script listener code - Duplicate active group to a new document.
// =================================================================
var idMk = charIDToTypeID( "Mk " );
var desc14 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref10 = new ActionReference();
var idDcmn = charIDToTypeID( "Dcmn" );
ref10.putClass( idDcmn );
desc14.putReference( idnull, ref10 );
var idUsng = charIDToTypeID( "Usng" );
var ref11 = new ActionReference();
var idLyr = charIDToTypeID( "Lyr " );
var idOrdn = charIDToTypeID( "Ordn" );
var idTrgt = charIDToTypeID( "Trgt" );
ref11.putEnumerated( idLyr, idOrdn, idTrgt );
desc14.putReference( idUsng, ref11 );
var idVrsn = charIDToTypeID( "Vrsn" );
desc14.putInteger( idVrsn, 5 );
executeAction( idMk, desc14, DialogModes.NO );
// Script listener code - Select first layer ( not counting Background layer).
// Just in case more than one layer was selected.
// ===========================================================================
var idslct = charIDToTypeID( "slct" );
var desc76 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref33 = new ActionReference();
var idLyr = charIDToTypeID( "Lyr " );
ref33.putName( idLyr, app.activeDocument.layers[0].name );
desc76.putReference( idnull, ref33 );
var idMkVs = charIDToTypeID( "MkVs" );
desc76.putBoolean( idMkVs, false );
executeAction( idslct, desc76, DialogModes.NO );
// Script listener code - Replace contents.
// =====================================================================
var idplacedLayerReplaceContents = stringIDToTypeID( "placedLayerReplaceContents" );
var desc8 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
desc8.putPath( idnull, new File( "~" ) );
executeAction( idplacedLayerReplaceContents, desc8, DialogModes.ALL );
// Script listener code - Select all layers again
// =======================================================
var idselectAllLayers = stringIDToTypeID( "selectAllLayers" );
var desc125 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref59 = new ActionReference();
var idLyr = charIDToTypeID( "Lyr " );
var idOrdn = charIDToTypeID( "Ordn" );
var idTrgt = charIDToTypeID( "Trgt" );
ref59.putEnumerated( idLyr, idOrdn, idTrgt );
desc125.putReference( idnull, ref59 );
executeAction( idselectAllLayers, desc125, DialogModes.NO );
// Script listener code - Duplicate active group to the prior document.
// =====================================================================
var idDplc = charIDToTypeID( "Dplc" );
var desc16 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref13 = new ActionReference();
var idLyr = charIDToTypeID( "Lyr " );
var idOrdn = charIDToTypeID( "Ordn" );
var idTrgt = charIDToTypeID( "Trgt" );
ref13.putEnumerated( idLyr, idOrdn, idTrgt );
desc16.putReference( idnull, ref13 );
var idT = charIDToTypeID( "T " );
var ref14 = new ActionReference();
var idDcmn = charIDToTypeID( "Dcmn" );
ref14.putName( idDcmn, docName );
desc16.putReference( idT, ref14 );
var idVrsn = charIDToTypeID( "Vrsn" );
desc16.putInteger( idVrsn, 5 );
executeAction( idDplc, desc16, DialogModes.NO );
// Closes the new document.
// =======================================================
app.activeDocument.close( SaveOptions.DONOTSAVECHANGES );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment