Copy link to clipboard
Copied
Hello,
I am looking for a Photoshop Script that gives my file a unique name, saves it, then closes it. I am a storyboard artist and I deal with several files and I am looking for a shortcut so that I don't have to manually name all my files. I just want to push a button and then it's named and saved automatically.
For example, I'm done drawing a panel, hit a button, then a files saves out as: "Panel_001.PSD" Then I draw another panel, I hit a button, and that panel saves out as "Panel_002.PSD" etc. etc.
Thank you.
if (app.documents.length) {
try { var f = app.activeDocument.fullName } catch (e) {
var p = new Folder; f = p.selectDlg(); if (f) f = File(f + '/' + app.activeDocument.name)
}
if (f) {
(o = new JPEGSaveOptions ()).quality = 12
activeDocument.saveAs(createUniqueFileName(f), o)
activeDocument.close()
}
}
function createUniqueFileName(f) {
var inPath = decodeURI(f.parent),
inFile = decodeURI(f.name).replace(/\.[^\.]+$/, '').replace(/_\d+$
...
Copy link to clipboard
Copied
From what it sounds like, you can create an action, but use the File>Automate>Batch command. Be sure to set the Source to Open Files.
Your action can use any naming convention you want, when you set it up.
Actions have a "button mode" option, so you can "hit a button"
Hope that helps.
Copy link to clipboard
Copied
You seem to have forgotten to talk about the location.
Copy link to clipboard
Copied
if (app.documents.length) {
try { var f = app.activeDocument.fullName } catch (e) {
var p = new Folder; f = p.selectDlg(); if (f) f = File(f + '/' + app.activeDocument.name)
}
if (f) {
activeDocument.saveAs(createUniqueFileName(f))
activeDocument.close()
}
}
function createUniqueFileName(f) {
var inPath = decodeURI(f.parent),
inFile = decodeURI(f.name).replace(/\.[^\.]+$/, '').replace(/_\d+$/,''),
inExt = '.psd',
uniqueFileName = File(inPath + '/' + inFile + inExt),
fileNumber = 1
while (uniqueFileName.exists) {
uniqueFileName = File(inPath + '/' + inFile + "_" + ('000' + fileNumber).slice(-3) + inExt)
fileNumber++;
}
return uniqueFileName
}
* saving only in psd (with default params) to the same folder from which the document was opened, or to the specified folder (if the document has not yet been saved)
Copy link to clipboard
Copied
DmitryEgorov
I find this script very interesting
I would need it for jpg files
you could edit it for me.
Copy link to clipboard
Copied
if (app.documents.length) {
try { var f = app.activeDocument.fullName } catch (e) {
var p = new Folder; f = p.selectDlg(); if (f) f = File(f + '/' + app.activeDocument.name)
}
if (f) {
(o = new JPEGSaveOptions ()).quality = 12
activeDocument.saveAs(createUniqueFileName(f), o)
activeDocument.close()
}
}
function createUniqueFileName(f) {
var inPath = decodeURI(f.parent),
inFile = decodeURI(f.name).replace(/\.[^\.]+$/, '').replace(/_\d+$/,''),
inExt = '.jpg',
uniqueFileName = File(inPath + '/' + inFile + inExt),
fileNumber = 1
while (uniqueFileName.exists) {
uniqueFileName = File(inPath + '/' + inFile + "_" + ('000' + fileNumber).slice(-3) + inExt)
fileNumber++;
}
return uniqueFileName
}
Copy link to clipboard
Copied
Thanks just what I was looking for
it works very well.
Copy link to clipboard
Copied
Would you mind editing this script for GIFs, please?
Copy link to clipboard
Copied
An alternative approach is to create a new document with the unique filename:
https://community.adobe.com/t5/photoshop/vba-to-javascript/m-p/10967341