Copy link to clipboard
Copied
Hello, greetings to all!
1- I open a document,
2- I Perform an action to set the color, size, and print type setting
3- I Merge all layers of the document, and rename it to: Print_A4-MD
4- Now I need to create a backup of this configured document for future impressions.
The first 3 steps I can perfectly with actions I recorded:
So I found a form that I like a lot:
When I select the "Print_A4-MD" layer and execute a Script, I save in the same directory a file named Print_A4-MD.jpg, containing the name of the selected layer.
My question is:
How to modify the script to save Print_A4-MD_01.jpg, Print_A4-MD_02.jpg, Print_A4-MD_03.jpg ..... whenever I re-run this script on the same selected layer ?? Thank you.
Here is the script for review:
// saves jpg into same folder;
// be advised: this overwrites existing jpgs of the same name without prompting.
// 2010, use it at your own risk;
#target photoshop;
if (app.documents.length > 0) {
var thedoc = app.activeDocument;
// getting the name and location;
var docName = thedoc.name;
if (docName.indexOf(".") != -1) {var basename = docName.match(/(.*)\.[^\.]+$/)[1]}
else {var basename = docName};
// getting the location, if unsaved save to desktop;
try {var docPath = thedoc.path}
catch (e) {var docPath = "~/Desktop"};
// jpg options;
var jpegOptions = new JPEGSaveOptions();
jpegOptions.quality = 9;
jpegOptions.embedColorProfile = true;
jpegOptions.matte = MatteType.NONE;
//save jpg as a copy:
thedoc.saveAs((new File(docPath+'/'+thedoc.activeLayer.name+'.jpg')),jpegOptions,true);
//that’s it; thanks to xbytor;
};
There you go.
...(function() {
try {
#target photoshop;
if (app.documents.length > 0) {
var thedoc = app.activeDocument;
// getting the name and location;
var docName = thedoc.name;
var basename = docName;
if (docName.indexOf(".") != -1)
basename = docName.match(/(.*)\.[^\.]+$/)[1]
// getting the location, if unsaved save to desktop;
var docPath = "~/Desktop";
try {
Copy link to clipboard
Copied
There you go.
(function() {
try {
#target photoshop;
if (app.documents.length > 0) {
var thedoc = app.activeDocument;
// getting the name and location;
var docName = thedoc.name;
var basename = docName;
if (docName.indexOf(".") != -1)
basename = docName.match(/(.*)\.[^\.]+$/)[1]
// getting the location, if unsaved save to desktop;
var docPath = "~/Desktop";
try {
docPath = thedoc.path;
} catch (e) {}
// jpg options;
var jpegOptions = new JPEGSaveOptions();
jpegOptions.quality = 9;
jpegOptions.embedColorProfile = true;
jpegOptions.matte = MatteType.NONE;
//save jpg as a copy:
var saveFile = docPath + '/' + thedoc.activeLayer.name + '.jpg';
if (File(saveFile).exists)
saveFile = incrementFile(saveFile);
thedoc.saveAs(new File(saveFile), jpegOptions, true);
//that’s it; thanks to xbytor;
};
function incrementFile(pathToFile) {
var saveSufixLength = 2,
suffix = zeroPad(0, saveSufixLength),
newPathToFile = pathToFile,
suffixInteger, folder, fileName, extension;
while (File(newPathToFile).exists) {
suffixInteger = parseInt(suffix, 10);
suffixInteger += 1;
suffix = zeroPad(suffixInteger, saveSufixLength);
folder = File(pathToFile).path;
fileName = File(pathToFile).name.substring(0, File(pathToFile).name.lastIndexOf("."));
extension = File(pathToFile).name.substring(File(pathToFile).name.lastIndexOf(".") + 1, File(pathToFile).name.length);
newPathToFile = folder + "/" + fileName + "_" + suffix + "." + extension;
}
return newPathToFile;
function zeroPad(num, digit) {
var tmp = num.toString();
while (tmp.length < digit) {
tmp = "0" + tmp;
}
return tmp;
}
}
} catch (e) {
alert(e.toString() + "\nScript File: " + File.decode(e.fileName).replace(/^.*[\|\/]/, '') +
"\nFunction: " + arguments.callee.name +
"\nError on Line: " + e.line.toString())
}
})();
Copy link to clipboard
Copied
It worked perfect! Forever grateful to you. I see almost all posts in this forum and I realize that you "Tomas Sinkunas " has collaborated very efficiently and helped a lot. Many thanks for the great help and congratulations for the work on After Efects.
www.rendertom.com
Copy link to clipboard
Copied
Thanks buddy.