Skip to main content
Participant
August 10, 2023
Answered

Scripts for Saving Targa (TGA) files to a known folder location.

  • August 10, 2023
  • 1 reply
  • 2148 views

I'm looking for a script that allows me to save a psd file as a TGA file.    The psd file will have the filename format of car_12345.psd and I'd like to be able to save it as car_12345.tga or in case 2 as car_spec_12345.tga. 

 

All tga files need to be saved to a C:\application\paint\<carmodel> folder where <carmodel> depends on the parent folder of car_12345.psd.      The parent folder could have a matching folder name but at the moment its just a design folder that holds resources used in the psd and back up files. 

 

I'd like to have the filesave dialog open in C:\application\paint\ or even better C:\application\paint\parent_folder.

 

I have found two helpful answers by @Kukurykus and @SuperMerlin (links below) but neither quite meet the brief.  

 

Looking for a script to save as targa file saves the file into the parent folder without any option for user interaction.

 

looking for a save as Targa script this adds a suffix and is closer in someways but how would I change the save as location?

 

Thanks Max.

This topic has been closed for replies.
Correct answer Stephen Marsh

@Max Pickle 

 

Do you really need the Save dialog window to open?

 

The following script will do what you request without the Save dialog window, "silently" saving to the required static output directory and creating the sub-directory based on the PSD parent directory name. You will be prompted to replace a file of the same name if it exists.

 

The naming is only for Case #1:

car_12345.tga

 

It isn't clear to me how Case #2 should be triggered:

car_spec_12345.tga

 

/*
Save TGA to Paint Folder.jsx
https://community.adobe.com/t5/photoshop-ecosystem-discussions/scripts-for-saving-targa-tga-files-to-a-known-folder-location/td-p/13998437
v1.1 - 11th August 2023, Stephen Marsh
*/

#target photoshop

(function () {

    if (app.documents.length > 0) {

        // Set the source doc parent folder name
        var sourceDirName = activeDocument.path.displayName;
        // Set the base save folder
        var thePath = "C:/application/paint";
        // Remove the file extension
        var docName = activeDocument.name.replace(/\.[^\.]+$/, '');
        // Base folder sub-folder from PSD folder name
        var destinationDir = new Folder(thePath + "/" + sourceDirName)
        if (!destinationDir.exists) {
            destinationDir.create()
        }
        var theFile = File(destinationDir + "/" + docName + ".tga");
        if (theFile.exists) {
            // true = 'No' as default active button
            if (!confirm("'" + theFile.name + "' exists, overwrite: Yes or No?", true))
                return;
        }

        SaveTARGA(theFile);


        function SaveTARGA(saveFile) {
            SaveOptions = new TargaSaveOptions();
            TargaSaveOptions.alphaChannels = true; // Include alpha channels, change to false for none
            TargaSaveOptions.resolution = TargaBitsPerPixels.TWENTYFOUR; // Options of SIXTEEN or THIRTYTWO
            TargaSaveOptions.rleCompression = true; // False for no compression
            activeDocument.saveAs(saveFile, TargaSaveOptions, true, Extension.LOWERCASE);
        }

    } else {
        alert("A document must be open to save a TGA file!");
    }

})();

 

1 reply

Stephen Marsh
Community Expert
Stephen MarshCommunity ExpertCorrect answer
Community Expert
August 11, 2023

@Max Pickle 

 

Do you really need the Save dialog window to open?

 

The following script will do what you request without the Save dialog window, "silently" saving to the required static output directory and creating the sub-directory based on the PSD parent directory name. You will be prompted to replace a file of the same name if it exists.

 

The naming is only for Case #1:

car_12345.tga

 

It isn't clear to me how Case #2 should be triggered:

car_spec_12345.tga

 

/*
Save TGA to Paint Folder.jsx
https://community.adobe.com/t5/photoshop-ecosystem-discussions/scripts-for-saving-targa-tga-files-to-a-known-folder-location/td-p/13998437
v1.1 - 11th August 2023, Stephen Marsh
*/

#target photoshop

(function () {

    if (app.documents.length > 0) {

        // Set the source doc parent folder name
        var sourceDirName = activeDocument.path.displayName;
        // Set the base save folder
        var thePath = "C:/application/paint";
        // Remove the file extension
        var docName = activeDocument.name.replace(/\.[^\.]+$/, '');
        // Base folder sub-folder from PSD folder name
        var destinationDir = new Folder(thePath + "/" + sourceDirName)
        if (!destinationDir.exists) {
            destinationDir.create()
        }
        var theFile = File(destinationDir + "/" + docName + ".tga");
        if (theFile.exists) {
            // true = 'No' as default active button
            if (!confirm("'" + theFile.name + "' exists, overwrite: Yes or No?", true))
                return;
        }

        SaveTARGA(theFile);


        function SaveTARGA(saveFile) {
            SaveOptions = new TargaSaveOptions();
            TargaSaveOptions.alphaChannels = true; // Include alpha channels, change to false for none
            TargaSaveOptions.resolution = TargaBitsPerPixels.TWENTYFOUR; // Options of SIXTEEN or THIRTYTWO
            TargaSaveOptions.rleCompression = true; // False for no compression
            activeDocument.saveAs(saveFile, TargaSaveOptions, true, Extension.LOWERCASE);
        }

    } else {
        alert("A document must be open to save a TGA file!");
    }

})();

 

Participant
August 11, 2023

Hi Stephen,  Thank you for the answer - I'll try it now.  

 

Save Dialog doesn't need to open if the PSD parent directory can be used. 

 

Case 2 can be its own script.   In the PSD there are 3 groups of layers.   Spec Map, Design Guides (Turn Off Before Exporting) and the Paintable Area.  Case 1 is the latter producing Car_12345 and Case 2 is the former producing Car_Spec_12345.  Often aspects of Case 1 are used to define Case2 so they are within the same PSD.  

Stephen Marsh
Community Expert
Community Expert
August 11, 2023
quote

Hi Stephen,  Thank you for the answer - I'll try it now.

 

Save Dialog doesn't need to open if the PSD parent directory can be used. 

 

I'll await your feedback...

 

 

Case 2 can be its own script.   In the PSD there are 3 groups of layers.   Spec Map, Design Guides (Turn Off Before Exporting) and the Paintable Area.  Case 1 is the latter producing Car_12345 and Case 2 is the former producing Car_Spec_12345.  Often aspects of Case 1 are used to define Case2 so they are within the same PSD.  


By @Max Pickle

 

I am not following, so just the same script, but the only difference would be that it adds Spec_ into the filename, nothing else? So this is manually selected to run, it isn't dependent on layer visibility or active layer etc?