Skip to main content
Known Participant
October 7, 2018
Answered

duplicate document and return

  • October 7, 2018
  • 1 reply
  • 1105 views

I do not know how to do this

I have an open document

I have to duplicate this document and apply some changes

in the end I applied the changes

I would like it to automatically come back to the original document

and delete the duplicate document.

This topic has been closed for replies.
Correct answer Stephen Marsh

this is not good

closes the document without saving the modified document

on the original document.

Maybe I explained myself wrong

the duplicate document

undergoes processing

at the end of the processing with the modification made

must return to the original document


Filed under the category of “be careful what you ask for, as you may receive it”…

this is not good

closes the document without saving the modified document

on the original document.

Exactly my point from the beginning of the topic thread! Which is why I commented and asked:

A STEP OR TWO APPEARS TO BE MISSING…

A COPY/PASTE OR APPLY IMAGE BETWEEN THE DUPE AND ORIGINAL?

NO SAVE OF THE DUPE BEFORE CLOSING? SO WHY BOTHER?

To which you replied:

but the thing is more complex and I do not know how to explain it

I put the simplest.

Can you now see how important it is to explain clearly what you want? I appreciate that English may not be your first language…

Maybe I explained myself wrong

Agreed.

the duplicate document

undergoes processing

at the end of the processing with the modification made

must return to the original document

Exactly how does the duplicate image that has undergone some unknown processing get returned to the original file?

A COPY/PASTE OR APPLY IMAGE BETWEEN THE DUPE AND ORIGINAL?

Can you perhaps show a screenshot image of the final result in the layers panel?

Here is the edited code:

#target photoshop 

var originalDoc = app.activeDocument;  

originalDoc.duplicate() // name parameters omitted in this simple example 

var dupedDoc = app.activeDocument;       

// Some unknown changes, somehow applied to something, somewhere…

dupedDoc.selection.selectAll();

dupedDoc.selection.copy(true); // merged copy = true

app.activeDocument = originalDoc

originalDoc.artLayers.add().name = 'Processed Layer';

originalDoc.paste();

app.purge (PurgeTarget.CLIPBOARDCACHE);

dupedDoc.close(SaveOptions.DONOTSAVECHANGES)

This code is making presumptions, so I have tried to make it as generic as possible without knowing your source and duplicate layer structure.

1 reply

Stephen Marsh
Community Expert
Community Expert
October 7, 2018

I have an open document

I have to duplicate this document and apply some changes

in the end I applied the changes

A STEP OR TWO APPEARS TO BE MISSING…

I would like it to automatically come back to the original document

A COPY/PASTE OR APPLY IMAGE BETWEEN THE DUPE AND ORIGINAL?

and delete the duplicate document.

NO SAVE OF THE DUPE BEFORE CLOSING? SO WHY BOTHER?

Known Participant
October 7, 2018

I understand what you mean

above I have set an example of what I would like to do

but the thing is more complex and I do not know how to explain it

I put the simplest.

Stephen Marsh
Community Expert
Community Expert
October 7, 2018

OK. I am a scripting newb, so perhaps a case of the blind leading the blind…

#target photoshop

var originalDoc = app.activeDocument;

originalDoc.duplicate() // name parameters omitted in this simple example

var dupedDoc = app.activeDocument;     

// Some unknown changes, somehow applied to something, somewhere…

app.activeDocument = originalDoc

dupedDoc.close(SaveOptions.DONOTSAVECHANGES)