Copy link to clipboard
Copied
Hi folks,
I´m looking for a script which does the following:
1. Save current view as JPG
2. Destination folder same as PSD
3. Naming "MN-$DATE-$PSD-NAME-$TIME" (e.g. MN-200508-ClientFlyer-172459)
I couldn´t find anything like this in the forum.
Would be such a great time saver for me!
(I´m working on Mac and Windows.)
Greets,
rufiooo
Hi,
Try following code, you may need to change the time format little bit but this will helpy you.
function exportToJPEG() {
var docName = app.activeDocument.name.split('.')[0];
var dateObj = new Date();
var year = dateObj.getFullYear().toString().substr(-2);
var month = ("0" + (dateObj.getMonth() + 1)).slice(-2);
var date = ("0" + dateObj.getDate()).slice(-2);
var time = dateObj.getTime();
var hours = dateObj.getHours()
var minutes= dateObj.getMinutes();
var
...
Copy link to clipboard
Copied
Hi,
Try following code, you may need to change the time format little bit but this will helpy you.
function exportToJPEG() {
var docName = app.activeDocument.name.split('.')[0];
var dateObj = new Date();
var year = dateObj.getFullYear().toString().substr(-2);
var month = ("0" + (dateObj.getMonth() + 1)).slice(-2);
var date = ("0" + dateObj.getDate()).slice(-2);
var time = dateObj.getTime();
var hours = dateObj.getHours()
var minutes= dateObj.getMinutes();
var seconds = dateObj.getSeconds();
var completeTime = hours.toString()+ minutes.toString()+ seconds.toString();
var completeDate = year.toString() + month.toString() + date.toString();
var fileName = app.activeDocument.path + "/" + "MN-" + completeDate + "-" + docName + "-" + completeTime + ".jpeg";
var idsave = stringIDToTypeID("save");
var desc5 = new ActionDescriptor();
var idas = stringIDToTypeID("as");
var desc6 = new ActionDescriptor();
var idextendedQuality = stringIDToTypeID("extendedQuality");
desc6.putInteger(idextendedQuality, 12);
var idscans = stringIDToTypeID("scans");
desc6.putInteger(idscans, 5);
var idmatteColor = stringIDToTypeID("matteColor");
var idmatteColor = stringIDToTypeID("matteColor");
var idnone = stringIDToTypeID("none");
desc6.putEnumerated(idmatteColor, idmatteColor, idnone);
var idJPEG = stringIDToTypeID("JPEG");
desc5.putObject(idas, idJPEG, desc6);
var idin = stringIDToTypeID("in");
desc5.putPath(idin, new File(fileName));
var iddocumentID = stringIDToTypeID("documentID");
desc5.putInteger(iddocumentID, 219);
var idlowerCase = stringIDToTypeID("lowerCase");
desc5.putBoolean(idlowerCase, true);
var idsaveStage = stringIDToTypeID("saveStage");
var idsaveStageType = stringIDToTypeID("saveStageType");
var idsaveSucceeded = stringIDToTypeID("saveSucceeded");
desc5.putEnumerated(idsaveStage, idsaveStageType, idsaveSucceeded);
executeAction(idsave, desc5, DialogModes.NO);
}
exportToJPEG();
Let us know if this helps you.
Thanks
Copy link to clipboard
Copied
So good! THANK YOU. It works perfectly.
Copy link to clipboard
Copied
Great! Glad it helps you.
Copy link to clipboard
Copied
Hi, I have a similar request
1. Save current view as JPG
2. Destination folder same as PSD
3. Name Add -01 to the files name
4. count up when I save another JPG from the same original file -02 -03 -04 etc
And since I don't know anything about scripting you may want to tell me where to paste the code you hopefully will be sending me.
Thank you, G
Copy link to clipboard
Copied
@Osog Ka – There are many scripts for this in the forum, one example:
#target photoshop
sequentialSave();
function sequentialSave() {
if (!documents.length) return;
var Name = app.activeDocument.name.replace(/\.[^\.]+$/, '');
try {
var savePath = activeDocument.path;
} catch (e) {
alert("You must save this document first!");
}
var fileList = savePath.getFiles("*.jpg").sort().reverse();
var Suffix = 0;
if (fileList.length) {
Suffix = Number(fileList[0].name.replace(/\.[^\.]+$/, '').match(/\d+$/));
}
Suffix = zeroPad(Suffix + 1, 3);
var saveFile = File(savePath + "/" + Name + "-" + Suffix + ".jpg");
SaveJPEG(saveFile, 8); // JPEG compression level
}
function SaveJPEG(saveFile, jpegQuality) {
jpgSaveOptions = new JPEGSaveOptions();
jpgSaveOptions.embedColorProfile = true;
jpgSaveOptions.formatOptions = FormatOptions.STANDARDBASELINE;
jpgSaveOptions.matte = MatteType.NONE;
jpgSaveOptions.quality = jpegQuality;
activeDocument.saveAs(saveFile, jpgSaveOptions, true, Extension.LOWERCASE);
}
function zeroPad(n, s) {
n = n.toString();
while (n.length < s) n = '0' + n;
return n;
}
This version uses Export - Save for Web:
#target photoshop
sequentialSave();
function sequentialSave() {
if (!documents.length) return;
var Name = app.activeDocument.name.replace(/\.[^\.]+$/, '');
try {
var savePath = activeDocument.path;
} catch (e) {
alert("You must save this document first!");
}
var fileList = savePath.getFiles("*.jpg").sort().reverse();
var Suffix = 0;
if (fileList.length) {
Suffix = Number(fileList[0].name.replace(/\.[^\.]+$/, '').match(/\d+$/));
}
Suffix = zeroPad(Suffix + 1, 3);
var saveFileJPEG = File(savePath + "/" + Name + "-" + Suffix + ".jpg");
SaveForWeb(saveFileJPEG);
}
// JPEG S4W Options
function SaveForWeb(saveFileJPEG) {
var sfwOptions = new ExportOptionsSaveForWeb();
sfwOptions.format = SaveDocumentType.JPEG;
sfwOptions.includeProfile = true;
sfwOptions.optimized = true;
sfwOptions.quality = 80;
app.activeDocument.exportDocument(saveFileJPEG, ExportType.SAVEFORWEB, sfwOptions);
}
function zeroPad(n, s) {
n = n.toString();
while (n.length < s) n = '0' + n;
return n;
}
Copy link to clipboard
Copied
Copy link to clipboard
Copied
OK, try this one, it is based on different code:
/* https://community.adobe.com/t5/photoshop/automate-save-as-or-export-with-sequential-file-names/m-p/9003836#M88140 */
// Stephen_A_Marsh
// 05-01-2021
// Additional options & menu add
// Rombout Versluijs
// 14-01-2021
// Usage
// - Because its being added to menu it can be hotkeyed
// - useFileName > true adds filename as a prefix
// - jpegQuality > sets save quality . range 1-12
// - formatOption > 1 Progressive
// 2 Optimized Baseline
// 3 Standard Baseline
/*
@@@BUILDINFO@@@ Quick Export as JPG Incremental.jsx 0.0.0.6
*/
/*
// BEGIN__HARVEST_EXCEPTION_ZSTRING
/*
<javascriptresource>
<name>$$$/JavaScripts/QuickExportAsJPGIncremental/Menu=Quick Export as JPG Incremental...</name>
<category>scriptexport</category>
<menu>export</menu>
<enableinfo>true</enableinfo>
</javascriptresource>
// END__HARVEST_EXCEPTION_ZSTRING
*/
// alert(documents.length)
#target photoshop
var useFileName = true; // true - false
var jpegQuality = 12; // 1-12
var formatOption = 1; // 1-3
/* Start Open/Saved Document Error Check - Part A: Try */
savedDoc();
function savedDoc() {
// try {
app.activeDocument.path;
/* Finish Open/Saved Document Error Check - Part A: Try */
/* Main Code Start */
// https://forums.adobe.com/message/4453915#4453915
main();
function main() {
if (!documents.length) return;
var Name = app.activeDocument.name.replace(/\.[^\.]+$/, '');
var savePath = activeDocument.path;
var fileList = [];
if (useFileName) {
var fileList = savePath.getFiles(Name + "*.jpg").sort().reverse();
} else {
var fileList = savePath.getFiles("*.jpg").sort().reverse();
var filtered = [];
for (i in fileList) {
var name = String(fileList[i]).split("/").pop(); // Get filename
name = name.slice(0, name.length - 4); // Split extension from name
// alert(name+" "+!isNaN(name))
// https://stackoverflow.com/questions/651563/getting-the-last-element-of-a-split-string-array
if (!isNaN(name)) filtered.push(name); // Check if name is a number or not > fullname needs to be numbers
}
}
var Suffix = 0;
if (fileList.length) {
if (useFileName) {
Suffix = fileList[0].name.replace(/\.[^\.]+$/, '').match(/\d+$/); // Fix for mix of characters & numbers
Suffix = Number(String(Suffix).slice(String(Suffix).length - 1, String(Suffix).length)); // Fix for Windows
// alert((fileList[0].name).slice(25,26))
// alert((fileList[0].name.replace(/\.[^\.]+$/, '').match(/\d+$/)).slice(fileList[0].name.length-5,fileList[0].name.length-4))
// alert((fileList[0].name.replace(/\.[^\.]+$/, '').match(/\d+$/)).slice(fileList[0].name.length-1,fileList[0].name.length))
// alert((fileList[0].name).slice(fileList[0].name.length-1,fileList[0].name.length))
// Suffix = Number(fileList[0].name.replace(/\.[^\.]+$/, '').match(/\d+$/)); // strips numbers when mixed
// Suffix = Number(fileList[0].name.match(/\d+$/)); // return true name even when mixed numbers and characters
} else if ((!filtered[0] === undefined) || filtered[0]) {
Suffix = Number(filtered[0].replace(/\.[^\.]+$/, '').match(/\d+$/));
}
}
Suffix = zeroPad(Suffix + 1, 3);
Name = useFileName ? (Name + "-") : "";
var saveFile = File(savePath + "/" + Name + Suffix + ".jpg");
SaveJPEG(saveFile, jpegQuality, formatOption);
}
function SaveJPEG(saveFile, jpegQuality, formatOption) {
jpgSaveOptions = new JPEGSaveOptions();
jpgSaveOptions.embedColorProfile = true;
if (formatOption === 1) {
jpgSaveOptions.formatOptions = FormatOptions.PROGRESSIVE;
jpgSaveOptions.scans = 3;
} else if (formatOption === 2) {
jpgSaveOptions.formatOptions = FormatOptions.OPTIMIZEDBASELINE;
} else {
jpgSaveOptions.formatOptions = FormatOptions.STANDARDBASELINE;
}
jpgSaveOptions.matte = MatteType.NONE;
jpgSaveOptions.quality = Number(jpegQuality);
activeDocument.saveAs(saveFile, jpgSaveOptions, true, Extension.LOWERCASE);
}
function zeroPad(n, s) {
n = n.toString();
while (n.length < s) n = '0' + n;
return n;
}
/* Main Code Finish */
// }
/* Start Open/Saved Document Error Check - Part B: Catch */
// catch (err) {
// alert(err)
// // alert("An image must be open and saved before running this script!");
// }
}
/* Finish Open/Saved Document Error Check - Part B: Catch */
I would suggest that you have zero padding before the version number, such as 001, 002 etc.
Copy link to clipboard
Copied
Hi @Charu Rajput, this is a fantastic script! I just had one question, is it possible to specify the time format?
Currently when I save, the time misses any leading zeroes.
For example 10.05AM becomes 105 rather than 1005. It just mucks up the order when I sort a folder by name.
Thank you!
Ashley
Copy link to clipboard
Copied
Use same format for minutes and seconds as used for month and date.
var minutes= ("0" + dateObj.getMinutes()).slice(-2);
var seconds = ("0" + dateObj.getSeconds()).slice(-2);
If required, you can change for hours as well in the similar way.
Copy link to clipboard
Copied