I have a large PSD which has approaching 100 top level groups. They're label designs, all of which are similar but with varying colours/patterns/text/images for the different parts of the label. Opening this PSD is taking longer and longer. Is there a way I can (relatively) quickly split the file into multiple PSDs, each of which contains one top level group?

  • 2
    With a script...
    – Joonas
    Dec 6 '14 at 15:03
  • Sounds great. Could you give me a pointer?
    – Echilon
    Dec 6 '14 at 15:38

This should get you close enough, if not all the way.

This script goes through every top level layer, duplicates them one by one into a new document and triggers an Action after each duplication.

var docName = app.activeDocument.name.split('.')[0];

for( var i = 0 ; i < app.activeDocument.layers.length; i++ ){

    app.activeDocument.activeLayer = app.activeDocument.layers[i];

    // =======================================================
    var idMk = charIDToTypeID( "Mk  " );
        var desc123 = new ActionDescriptor();
        var idnull = charIDToTypeID( "null" );
            var ref86 = new ActionReference();
            var idDcmn = charIDToTypeID( "Dcmn" );
            ref86.putClass( idDcmn );
        desc123.putReference( idnull, ref86 );
        var idNm = charIDToTypeID( "Nm  " );
        desc123.putString( idNm, docName +' '+ ( i + 1 ) );
        var idUsng = charIDToTypeID( "Usng" );
            var ref87 = new ActionReference();
            var idLyr = charIDToTypeID( "Lyr " );
            var idOrdn = charIDToTypeID( "Ordn" );
            var idTrgt = charIDToTypeID( "Trgt" );
            ref87.putEnumerated( idLyr, idOrdn, idTrgt );
        desc123.putReference( idUsng, ref87 );
        var idVrsn = charIDToTypeID( "Vrsn" );
        desc123.putInteger( idVrsn, 5 );
    executeAction( idMk, desc123, DialogModes.NO );

    doAction('Loop Layers', 'Loop Layers');


All you need next is to create an Action called Loop Layers in a folder called Loop Layers.

The naming is important, because it's hard coded into the script.

What you need to record into the action is this:

  1. Image > Trim ( Optional )
  2. File > Save as... ( Select the location and file format. Just don't touch the filename at all )
  3. File > Close ( Technically optional, but you'll likely want to do this. Make sure that when you record this part, it asks "Save changes before closing..." and you press "No". You can make sure that it asks you by making changes to the document before recording this. ).

The duplication part of the script makes sure that each duplicate document gets a filename based on the original document name + a subsequent number based on the loop cycle. This makes sure that when the files are saved, the filenames are unique.

A little preview of what the script does.

enter image description here

  • In case someone is wondering... The Action part of this could all have been coded into the script. I just figured dividing it into a script and action would give the used more freedom without having to modify the code.
    – Joonas
    Dec 6 '14 at 19:21

If you happen to be less comfortable with scripts and looking for another option, you should know that when you duplicate a layer or a group, you can always pinpoint to send it to another destination document. You could probably streamline some of the process with actions.

Also, if you have a destination document open, you can grab the group to the other document while holding shift so that it will paste in the same place.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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