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

remove copy when I duplicate document

Enthusiast ,
Jan 29, 2024 Jan 29, 2024

there is a way to
remove copy when I duplicate document?

 

TOPICS
Actions and scripting
1.5K
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

correct answers 3 Correct answers

Community Expert , Jan 29, 2024 Jan 29, 2024

A script can do that:

 

activeDocument.duplicate(activeDocument.name.replace(/\.[^\.]+$/, ''), false);

 

or

 

activeDocument.duplicate(activeDocument.name, false);
Translate
Enthusiast , Jan 29, 2024 Jan 29, 2024

c.pfaffenbichler
Thanks for your help
I have successfully solved this problem

this is the solution if anyone wants to use it in the future

 

async function  DUPLICADOC() {
const ps = require('photoshop');
const myDoc = app.activeDocument;
const executeAsModal = ps.core.executeAsModal;
await executeAsModal(async () => {
  await ps.app.activeDocument.duplicate(myDoc.name, false)
}, {})
}

 

Translate
Community Expert , Jan 30, 2024 Jan 30, 2024

Hi @c.pfaffenbichler,

I'd do it like this:

 

 

const { app, core } = require("photoshop");
await core.executeAsModal( async () => {
  app.activeDocument.duplicate(app.activeDocument.name, true);
}, { commandName: "Duplicate with the same name" });

 

 

Which seems exactly what @Ciccillotto is using 👌🏻
The boolean is for merged layers, like in ExtendScript, BTW.

 

 

Translate
Adobe
Community Expert ,
Jan 29, 2024 Jan 29, 2024

@Ciccillotto you can do that from the layers panel flyout menu, if that's what you mean.

2024-01-29 12_50_21-Untitled-1 @ 50% (RGB_8).png

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 ,
Jan 29, 2024 Jan 29, 2024

In the preferences, under file handling, check the box that says: "Do not append 'copy' to filename when saving a copy."

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
Enthusiast ,
Jan 29, 2024 Jan 29, 2024

I didn't explain myself well when I duplicate the document the word copy comes out.

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 ,
Jan 29, 2024 Jan 29, 2024

A script can do that:

 

activeDocument.duplicate(activeDocument.name.replace(/\.[^\.]+$/, ''), false);

 

or

 

activeDocument.duplicate(activeDocument.name, false);
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 ,
Jan 29, 2024 Jan 29, 2024

In the future please try to post meaningful screenshots including the pertinent Panels/dialogs to clarify what you are talking about. 

 

The » copy« does indeed not add a lot of relevant information but do you really just want the new, unsaved image to have the same name as the original?

Do you want to save it right away to some relative location, add some other name-element, …? 

 

And please remember to mark @Stephen Marsh ’s post as »Correct Answer«. 

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
Enthusiast ,
Jan 29, 2024 Jan 29, 2024

c.pfaffenbichler
you're right but I was on a cell phone and couldn't add screenshots

Unfortunately, having little uxp documentation, I try to adapt the gaps with javascript
I'm trying to create a button in uxp that saves the document with a progressive number,
when I save as jpg it's fine
unfortunately when I want to save in psd this saves it with a progressive number like pippo.1.jpg
then if I save it again it does this to me
pippo.1_2.jpg then pippo.1_2_3.jpg and continue like this with each save.
so I'm trying to solve it this way
I duplicate the document, save inpsd and close the document,
this seems to work,

now I just need to figure out how to make this string work in uxp
activeDocument.duplicate(activeDocument.name.replace(/\.[^\.]+$/, ''), false);

 

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 ,
Jan 29, 2024 Jan 29, 2024

I am not up-to-speed with UXP Scripting, still stuck with ESTK … hopefully someone else can chime in. 

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
Enthusiast ,
Jan 29, 2024 Jan 29, 2024

Unfortunately, even if uxp will be the future, I see it as very immature, the potential is there but for now javascript is superior in every way
for example this one in javascript is disarmingly simple
activeDocument.duplicate(activeDocument.name, false);
if I can get it to work with uxp it will definitely have a lot of excess code.

however this community is always kind and willing to help unlike the uxp forum which are reluctant to give info,

 

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 ,
Jan 29, 2024 Jan 29, 2024

@DavideBarranca , please forgive another intrusion; could you chime in on short/efficient UXP-code for this task? 

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
Enthusiast ,
Jan 29, 2024 Jan 29, 2024

c.pfaffenbichler
Thanks for your help
I have successfully solved this problem

this is the solution if anyone wants to use it in the future

 

async function  DUPLICADOC() {
const ps = require('photoshop');
const myDoc = app.activeDocument;
const executeAsModal = ps.core.executeAsModal;
await executeAsModal(async () => {
  await ps.app.activeDocument.duplicate(myDoc.name, false)
}, {})
}

 

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 ,
Jan 30, 2024 Jan 30, 2024

Hi @c.pfaffenbichler,

I'd do it like this:

 

 

const { app, core } = require("photoshop");
await core.executeAsModal( async () => {
  app.activeDocument.duplicate(app.activeDocument.name, true);
}, { commandName: "Duplicate with the same name" });

 

 

Which seems exactly what @Ciccillotto is using 👌🏻
The boolean is for merged layers, like in ExtendScript, BTW.

 

 

Davide Barranca - PS developer and author
www.ps-scripting.com
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 ,
Jan 30, 2024 Jan 30, 2024

@Davide_Barranca - Is the code for a panel or script? I saved the code from @Ciccillotto as a .psjs file, but nothing happened when run from Ps 2024 File > Scripts > Browse...

 

EDIT:

 

This works as .psjs:

 

 

app.activeDocument.duplicate(app.activeDocument.name, true);

 

or

 

app.activeDocument.duplicate(app.activeDocument.name.replace(/\.[^\.]+$/, ''), true);

 

 

 

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
Enthusiast ,
Jan 30, 2024 Jan 30, 2024

I have to use it for a panel I don't know if it works for psjs

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 ,
Jan 30, 2024 Jan 30, 2024
quote

I have to use it for a panel I don't know if it works for psjs


By @Ciccillotto

 

Thanks, I understand, for now I'm not interested in panel development – but I may be tempted to dip my toe into the pond with UXP scripting.

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 ,
Jan 30, 2024 Jan 30, 2024

Mine works if saved as a `.psjs`.
@Ciccillotto 's is missing the `commandName` prop in the options object (an empty one is fine, according to the docs) but lacks the function call to `DUPLICADOC()`

Davide Barranca - PS developer and author
www.ps-scripting.com
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 ,
Jan 30, 2024 Jan 30, 2024

Thanks David!

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
Enthusiast ,
Jan 30, 2024 Jan 30, 2024

@DavideBarranca I was wondering if there is a way to call back via uxp button a psjs file, I tried a couple of ways but it doesn't work, you have faced this problem.

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 ,
Jan 31, 2024 Jan 31, 2024
LATEST

@Ciccillotto I don't think so, but you can try to batchPlay the File > Script > Browse... and point to a `file:`, but be aware that there are manifest permissions to set, unless the file is in the plugin's sandbox. Adobe did something to restrict that Browse... call for JSX, IIRC, so it may or may not work (can't test now)

Davide Barranca - PS developer and author
www.ps-scripting.com
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 ,
Jan 30, 2024 Jan 30, 2024

Thank you! 

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