Copy link to clipboard
Copied
there is a way to
remove copy when I duplicate document?
A script can do that:
activeDocument.duplicate(activeDocument.name.replace(/\.[^\.]+$/, ''), false);
or
activeDocument.duplicate(activeDocument.name, false);
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)
}, {})
}
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.
Copy link to clipboard
Copied
@Ciccillotto you can do that from the layers panel flyout menu, if that's what you mean.
Copy link to clipboard
Copied
In the preferences, under file handling, check the box that says: "Do not append 'copy' to filename when saving a copy."
Copy link to clipboard
Copied
I didn't explain myself well when I duplicate the document the word copy comes out.
Copy link to clipboard
Copied
A script can do that:
activeDocument.duplicate(activeDocument.name.replace(/\.[^\.]+$/, ''), false);
or
activeDocument.duplicate(activeDocument.name, false);
Copy link to clipboard
Copied
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_A_Marsh ’s post as »Correct Answer«.
Copy link to clipboard
Copied
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);
Copy link to clipboard
Copied
I am not up-to-speed with UXP Scripting, still stuck with ESTK … hopefully someone else can chime in.
Copy link to clipboard
Copied
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,
Copy link to clipboard
Copied
@DavideBarranca , please forgive another intrusion; could you chime in on short/efficient UXP-code for this task?
Copy link to clipboard
Copied
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)
}, {})
}
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
@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);
Copy link to clipboard
Copied
I have to use it for a panel I don't know if it works for psjs
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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()`
Copy link to clipboard
Copied
Thanks David!
Copy link to clipboard
Copied
@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.
Copy link to clipboard
Copied
@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)
Copy link to clipboard
Copied
Thank you!