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

Save an unopened document

Engaged ,
Feb 09, 2019 Feb 09, 2019

Copy link to clipboard

Copied

Hello everyone,

I have this script: I select a folder, open only tif and psd in it (subfolders included), then if a file contains a substring in it, it changes the name (removes the substring), then it saves as tif with the new name, saves as jpg 5 with the new name, then deletes the original file.

my problem is near the bottom, lines 64 and 74. I have this 2 functions to save tiff and save jpeg that I use a lot, and this is the first time I tried to save tiff or jpeg while the document isn't open. is it possible to save tiff or jpeg when the document is not open?

#target photoshop

// Select folder dialog, open only tif and psd, if contains the substring: change the name: save tif, save jpg 5, then delete the file.

var theFolder = Folder.selectDialog("select folder");

var fileandfolderAr = scanSubFolders(theFolder,/\.(tif|psd)$/i);                //var fileandfolderAr = scanSubFolders(topFolder,/\.(jpg|tif|psd|bmp|gif|png|)$/i);

var fileList = fileandfolderAr[0];

var substring = "-temp";

for (var a = 0 ;a < fileList.length; a++)

{

var Name = fileList.name;

if (Name.match(substring))

{       

           

        Name = Name.replace(substring,'');

   

        var savePath = fileList.path;      

        var saveName = File(savePath + "/" + Name) 

        SaveTIFF(saveName);

        SaveJPEG(saveName,5);

        fileList.remove();

}

}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function scanSubFolders(tFolder, mask) { // folder object, RegExp or string

    var sFolders = new Array();

    var allFiles = new Array();

    sFolders[0] = tFolder;

    for (var j = 0; j < sFolders.length; j++){ // loop through folders           

        var procFiles = sFolders.getFiles();

        for (var i=0;i<procFiles.length;i++){ // loop through this folder contents

            if (procFiles instanceof File ){

                if(mask==undefined) allFiles.push(procFiles);// if no search mask collect all files

                if (procFiles.fullName.search(mask) != -1) allFiles.push(procFiles); // otherwise only those that match mask

        }else if (procFiles instanceof Folder){

            sFolders.push(procFiles);// store the subfolder

            scanSubFolders(procFiles, mask);// search the subfolder

         }

      }

   }

   return [allFiles,sFolders];

};

function SaveTIFF(saveFile){ 

tiffSaveOptions = new TiffSaveOptions();  

tiffSaveOptions.embedColorProfile = true;  

tiffSaveOptions.alphaChannels = true;  

tiffSaveOptions.layers = true; 

tiffSaveOptions.imageCompression = TIFFEncoding.NONE;   

activeDocument.saveAs(saveFile, tiffSaveOptions, true, Extension.LOWERCASE);  

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

    };   

TOPICS
Actions and scripting

Views

313

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
no replies

Have something to add?

Join the conversation
Adobe