Skip to main content
Participant
May 25, 2020
Question

Photoshop Actions - Duplicate to Other Document

  • May 25, 2020
  • 3 replies
  • 1306 views

I'm trying to create an action that can do the following:

  • Duplicate the currently selected layer to a different document
  • Close the current document

The document that I'm copying to changes, so I wanted to use 'toggle dialog' and manually select the document each time; However, I can't get it to toggle on.

 

I've used that feature for changing the names of files being saved and other things before.  I'm not sure why I'm not able to use it in this instance?

This topic has been closed for replies.

3 replies

Stephen Marsh
Community Expert
Community Expert
June 2, 2020

Hi faile486 are you still out there?

 

 

#target photoshop

// Set the source doc
var sourceDoc = app.activeDocument;

// Dupe active layer with dialog
dupeLayer();

// Close source doc
sourceDoc.close(SaveOptions.PROMPTTOSAVECHANGES);
/*
sourceDoc.close(SaveOptions.SAVECHANGES);
sourceDoc.close(SaveOptions.DONOTSAVECHANGES);
*/

// Function created with xtools!
function dupeLayer() {
    function step1(enabled, withDialog) {
    if (enabled !== undefined && !enabled)
      return;
    var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
    var desc1 = new ActionDescriptor();
    var ref1 = new ActionReference();
    ref1.putEnumerated(cTID('Lyr '), cTID('Ordn'), cTID('Trgt'));
    desc1.putReference(cTID('null'), ref1);
    executeAction(cTID('Dplc'), desc1, dialogMode);
  }
  step1(true, true);
}

 

 

https://prepression.blogspot.com/2017/11/downloading-and-installing-adobe-scripts.html?m=1

 

Charu Rajput
Community Expert
Community Expert
May 27, 2020

Hi,

If I understand your workfllow correctly, then may be following script will help you to duplicate the document and close the source document. The following snippet will duplicate the seleted layer to the new document if the documentName mention in the script(Here "TestDocument" is the name of teh document you can name anything) is not opened in the photoshop. I am not sure how much you are aware of the Javascript scripting, but if you know then you can modify it as per your requirements. 

 

function duplicateLayer(docName) {
    try {
        var idduplicate = stringIDToTypeID("duplicate");
        var desc59 = new ActionDescriptor();
        var idnull = stringIDToTypeID("null");
        var ref26 = new ActionReference();
        var idlayer = stringIDToTypeID("layer");
        var idordinal = stringIDToTypeID("ordinal");
        var idtargetEnum = stringIDToTypeID("targetEnum");
        ref26.putEnumerated(idlayer, idordinal, idtargetEnum);
        desc59.putReference(idnull, ref26);
        var idto = stringIDToTypeID("to");
        var ref27 = new ActionReference();
        var iddocument = stringIDToTypeID("document");
        ref27.putName(iddocument, docName);
        desc59.putReference(idto, ref27);
        var idversion = stringIDToTypeID("version");
        desc59.putInteger(idversion, 5);
        var idID = stringIDToTypeID("ID");
        var list5 = new ActionList();
        list5.putInteger(2);
        desc59.putList(idID, list5);
        executeAction(idduplicate, desc59, DialogModes.NO);
    } catch (e) {
        var idmake = stringIDToTypeID("make");
        var desc31 = new ActionDescriptor();
        var idnull = stringIDToTypeID("null");
        var ref15 = new ActionReference();
        var iddocument = stringIDToTypeID("document");
        ref15.putClass(iddocument);
        desc31.putReference(idnull, ref15);
        var idusing = stringIDToTypeID("using");
        var ref16 = new ActionReference();
        var idlayer = stringIDToTypeID("layer");
        var idordinal = stringIDToTypeID("ordinal");
        var idtargetEnum = stringIDToTypeID("targetEnum");
        ref16.putEnumerated(idlayer, idordinal, idtargetEnum);
        desc31.putReference(idusing, ref16);
        var idversion = stringIDToTypeID("version");
        desc31.putInteger(idversion, 5);
        executeAction(idmake, desc31, DialogModes.NO);
    }
}

function closeDocument(doc) {
    doc.close(SaveOptions.DONOTSAVECHANGES);
}

function main() {
    var doc = app.activeDocument;
    // Make sure a document with name "TestDocument" is open, otherwise it will create a new document automatically
    var destinationDocName = 'TestDocument';
    duplicateLayer(destinationDocName);
    closeDocument(doc);
}

main();

 

Let us know if this helps you.

Best regards
Stephen Marsh
Community Expert
Community Expert
May 25, 2020

Don't record the step, use the action panel menu to "insert menu command".

 

That being said, depending on your workflow, a script may be better.