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

Create a copy of the current document in a subfolder as the tiff format

Engaged ,
Nov 20, 2017 Nov 20, 2017

Hello! This script creates a copy.jpg of the current document in the same folder with the name of the active layer. How do I modify this script so that it works as follows:

• Whenever I run this script, a copy is no longer jpg but a copy.tiff of the current document with the name of the active layer inside a subfolder called "Rolad Prints"

Script: Can anyone guide me? Thank you

// Backup_Estampa

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

    } 

})();

TOPICS
Actions and scripting
852
Translate
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

People's Champ , Nov 20, 2017 Nov 20, 2017

Check. This is it or not?

var subfolder = "Rolad Prints";

var tif_layers = true; // change to false if you want flatten image

// Backup_Estampa

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

              

...
Translate
Adobe
People's Champ ,
Nov 20, 2017 Nov 20, 2017

Check. This is it or not?

var subfolder = "Rolad Prints";

var tif_layers = true; // change to false if you want flatten image

// Backup_Estampa

(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) {}   

              

            // tif options;      

            var tiffOptions = new TiffSaveOptions();   

            with (tiffOptions)

                {

                alphaChannels      = true;

                annotations        = true;

                byteOrder          = ByteOrder.IBM;

                embedColorProfile  = true;

                imageCompression   = TIFFEncoding.NONE;

                interleaveChannels = true;

                jpegQuality        = 12;

                layerCompression   = LayerCompression.ZIP;

                layers             = tif_layers;

                saveImagePyramid   = false;

                spotColors         = true;

                transparency       = false;

                }

              

            //save tif as a copy:   

            if (!Folder(docPath + "/" + subfolder).exists) Folder(docPath + "/" + subfolder).create();

            var saveFile = docPath + '/' + subfolder + '/' + thedoc.activeLayer.name + '.tif';   

            if (File(saveFile).exists)   

                saveFile = incrementFile(saveFile);   

              

            thedoc.saveAs(new File(saveFile), tiffOptions, 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 + "/" + subfolder + "/" + 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())   

    }   

})();  

Translate
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
Engaged ,
Nov 20, 2017 Nov 20, 2017
LATEST

Wow, perfect! r-bin you are phenomenal. You can not imagine how much this will expedite my tasks. Thank you so much.

Translate
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