Copy link to clipboard
Copied
I'm looking for a script that can save an open, previously unsaved, image as a TIFF file.
It's important that it's not needed to enter a new file name every single time the script is executed, I need the script to do that for me, at least once a file name is pre-defined in the script.
The script must also automatically "number" the files like file0001.tif, file0002.tif,, file0003.tif, etc., in order to not overwrite an already existing file.
Is there a script that fits my description?
Cheers!
Martin
I think this should do it (not tested)....
...#target photoshop
app.bringToFront();
main();
function main(){
if(!documents.length) return;
//amend to suit
var folderPath = Folder("/c/folderName");
if(!folderPath.exists) {
alert("Output folder does not exist!");
return;
}
//this should be the first part of the filename
//I.E. if file name = Picture0001.tif it needs to be Picture
//N.B. it must be the same case!
var fileName = "filename";
var fileType = "tif";
var fileList = new Array();
var newNumber=0;
Copy link to clipboard
Copied
Please try this, you will have to edit the script to meet your needs.
It will save ALL open documents an close them once saved.
#target photoshop
app.bringToFront();
main();
function main(){
if(!documents.length) return;
//amend to suit
var folderPath = Folder("/c/folderName");
if(!folderPath.exists) {
alert("Output folder does not exist!");
return;
}
//this should be the first part of the filename
//I.E. if file name = Picture0001.tif it needs to be Picture
//N.B. it must be the same case!
var fileName = "filename";
var fileType = "tif";
while (documents.length) {
var fileList = new Array();
var newNumber=0;
var saveFile='';
fileList = folderPath.getFiles((fileName + "*." + fileType));
fileList.sort().reverse();
if(fileList.length == 0){
saveFile=File(folderPath + "/" + fileName + "0001." +fileType);
SaveTIFF(saveFile);
activeDocument.close(SaveOptions.DONOTSAVECHANGES);
}else{
newNumber = Number(fileList[0].toString().replace(/\....$/,'').match(/\d+$/)) +1;
saveFile=File(folderPath + "/" + fileName + zeroPad(newNumber, 4) + "." +fileType);
SaveTIFF(saveFile);
activeDocument.close(SaveOptions.DONOTSAVECHANGES);
}
}
};function zeroPad(n, s) {
n = n.toString();
while (n.length < s) n = '0' + n;
return n;
};
function SaveTIFF(saveFile){
tiffSaveOptions = new TiffSaveOptions();
tiffSaveOptions.embedColorProfile = true;
tiffSaveOptions.alphaChannels = true;
tiffSaveOptions.layers = true;
tiffSaveOptions.imageCompression = TIFFEncoding.TIFFLZW;
activeDocument.saveAs(saveFile, tiffSaveOptions, true, Extension.LOWERCASE);
};
Copy link to clipboard
Copied
Thanks for the reply and the script Paul!
I just tried it and it does indeed save all open documents and closing them.
Is it possible to make the script only save the document that is being working on, the one that's selected at the bottom in the "Window" menu?
Also, it is possible to not closing all documents, not even the one it has saved? Because the closing command can easily be added with actions and I rather do it that way, so I can chose to either close it or not.
Martin
Copy link to clipboard
Copied
I think this should do it (not tested)....
#target photoshop
app.bringToFront();
main();
function main(){
if(!documents.length) return;
//amend to suit
var folderPath = Folder("/c/folderName");
if(!folderPath.exists) {
alert("Output folder does not exist!");
return;
}
//this should be the first part of the filename
//I.E. if file name = Picture0001.tif it needs to be Picture
//N.B. it must be the same case!
var fileName = "filename";
var fileType = "tif";
var fileList = new Array();
var newNumber=0;
var saveFile='';
fileList = folderPath.getFiles((fileName + "*." + fileType));
fileList.sort().reverse();
if(fileList.length == 0){
saveFile=File(folderPath + "/" + fileName + "0001." +fileType);
SaveTIFF(saveFile);
}else{
newNumber = Number(fileList[0].toString().replace(/\....$/,'').match(/\d+$/)) +1;
saveFile=File(folderPath + "/" + fileName + zeroPad(newNumber, 4) + "." +fileType);
SaveTIFF(saveFile);
}
};function zeroPad(n, s) {
n = n.toString();
while (n.length < s) n = '0' + n;
return n;
};
function SaveTIFF(saveFile){
tiffSaveOptions = new TiffSaveOptions();
tiffSaveOptions.embedColorProfile = true;
tiffSaveOptions.alphaChannels = true;
tiffSaveOptions.layers = true;
tiffSaveOptions.imageCompression = TIFFEncoding.TIFFLZW;
activeDocument.saveAs(saveFile, tiffSaveOptions, true, Extension.LOWERCASE);
};
Copy link to clipboard
Copied
Wow! Paul, you're a genius! Haha, you should see me smiling now.
Thanks sooo much for the script! It is perfect (full score!) and it is greatly appreciated. It just made my life easier, I assure you that!
About 700-900 files to save - here I come!
Regards
Martin
Copy link to clipboard
Copied
I know this is a old thread, but is there a way to "prompt" the user for the folder location to save the file to (using the save as dialog box)?
Copy link to clipboard
Copied
Change line 7 From
var folderPath = Folder("/c/folderName");
To
var folderPath = Folder.selectDialog("Please select the output folder");
Copy link to clipboard
Copied
Paul, your script is just what I am looking for except I want to save the files as jpg files. What lines do I need to change.
Thank you.
Copy link to clipboard
Copied
Paul stopped coming here a couple years ago. Just search this forum for code the does a Save As Jpeg and adapt the code into Pauls script.
https://forums.adobe.com/search.jspa?place=%2Fplaces%2F1383833&sort=updatedDesc&q=code+Save+As+Jpeg
https://forums.adobe.com/search.jspa?place=%2Fplaces%2F1383833&sort=updatedDesc&q=code+Save+As+Jpg