Thank you!
Maybe I'm not understanding how to add the script into my action because the action is running but it is not following the script you have helped make for me.
This is what I have done, I am using NOTEPAD and saving as a .jsx file on Windows 10. **and not as .jsx.txt only .jsx
If Notepad is the wrong program let me know.
The steps I follow are below:
I take your script, copy into notepad: -->
- var doc = app.activeDocument;
- var uniqueDigits = doc.name.replace(/(^.+_)(\d+)(\.[^\.]+$)/, '$2');
- var newName = 'custom name_' + uniqueDigits + '.jpg';
Changed your line #5 to my own text: -->
5. var newName = 'MODELNAME_' + uniqueDigits + '.jpg';
Save as .jsx in script folder of Photoshop CC 2019: -->
Then I add the script into my action:
- Convert to procfile current document
- Convert mode
- image size
- set background
- make text layer
- flatten image
- Scripts ((this is where I found the script by FILE>SCRIPTS>BROWSE))
- Save As - ((here I do not change document name, just save as the original title))
- close
Maybe it's in the Save As & Close steps that there is an issue, but when I delete these steps the file then doesn't save at all
When I run your script with the steps above but with Save As & Close, it runs all parts of the action except changing the name. And the files save it still says DSC at final output.
At least on my part, the assumption/expectation was that the code snippets would be incorporated into a larger script, not referenced in an action as is.
As Chuck said, you would need to add code to save as a JPEG and reference the name with additional code.
An alternative is to use additional code that will duplicate using the required new filename, then an action or a file processing script could be used to save the file/s.
EDIT – Something like this, where the original file is duplicated with the new static+variable name and the original file is closed:
#target photoshop
// Dupe Original File with Prefix.jsx
var origDoc = app.activeDocument
var uniqueDigits = origDoc.name.replace(/(^.+_)(\d+)(\.[^\.]*$)/, '$2');
var newName = 'MODELNAME_' + uniqueDigits;
origDoc.duplicate((newName), true); // Change to false to retain layers
// (SaveOptions.SAVECHANGES)
origDoc.close(SaveOptions.DONOTSAVECHANGES);