• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Script to save previously unsaved, newly created files?

Explorer ,
Apr 13, 2013 Apr 13, 2013

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

TOPICS
Actions and scripting

Views

3.2K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Valorous Hero , Apr 13, 2013 Apr 13, 2013

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;

...

Votes

Translate

Translate
Adobe
Valorous Hero ,
Apr 13, 2013 Apr 13, 2013

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);
};


Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 13, 2013 Apr 13, 2013

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Apr 13, 2013 Apr 13, 2013

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);
};


Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 13, 2013 Apr 13, 2013

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 18, 2015 Mar 18, 2015

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)?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Mar 18, 2015 Mar 18, 2015

Copy link to clipboard

Copied

Change line 7 From

var folderPath = Folder("/c/folderName");

To

var folderPath =  Folder.selectDialog("Please select the output folder");

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 02, 2016 Feb 02, 2016

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 02, 2016 Feb 02, 2016

Copy link to clipboard

Copied

LATEST

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

JJMack

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines