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

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

Community Beginner ,
Aug 10, 2023 Aug 10, 2023

Copy link to clipboard

Copied

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.

TOPICS
Actions and scripting

Views

571

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

Community Expert , Aug 10, 2023 Aug 10, 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.js
...

Votes

Translate

Translate
Adobe
Community Expert ,
Aug 10, 2023 Aug 10, 2023

Copy link to clipboard

Copied

@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!");
    }

})();

 

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 ,
Aug 10, 2023 Aug 10, 2023

Copy link to clipboard

Copied

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.  

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 ,
Aug 10, 2023 Aug 10, 2023

Copy link to clipboard

Copied

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?

 

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 ,
Aug 10, 2023 Aug 10, 2023

Copy link to clipboard

Copied

Hi Stephen,  Thanks again, super helpful and saved me hours of trawling the web 🙂

 

It worked almost perfectly out the box and I was able to create the spec version from what you gave me.    I had to comment out throw null as it threw an error.   For the spec version I just added this line and swapped the File Destination accordingly. 

 

var newDocName = docName.replace("_", "_spec_");

 

Note for anyone else copying and pasting the folder path from explorer into this script.  You need to get the slashes going in the right direction!

 

Is it written in pure javascript or an Adobe variant?   

 

Thanks again,

Max

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 ,
Aug 11, 2023 Aug 11, 2023

Copy link to clipboard

Copied

Glad to help Max, it was easier for me to build it from scratch than to hack away at the scripts that you posted links to.

 

You may have noticed that I have tidied up the code a bit and now give it an "official" v1.0 version control stamp!

 

You could get rid of the entire if block for prompting to overwrite. I'll see if I can trigger the error and post an update, I obviously didn't have any issues in my tests. Was this error with the code I posted, or after you edited it for the #2 case version.

 

It's also possible to have a single script, where you can hold down a key modifier like SHIFT or ALT/OPT to run the case #2 code.

 

The code is all Adobe ExtendScript (JS) using standard DOM code (without any esoteric Action Manager code).

 

 

 

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 ,
Aug 11, 2023 Aug 11, 2023

Copy link to clipboard

Copied

@Max Pickle – I have updated the code to a 1.1 version which should hopefully remove the error if no is pressed to avoid overwriting an existing file. Would you be able to test and confirm?

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 ,
Aug 11, 2023 Aug 11, 2023

Copy link to clipboard

Copied

Hi Stephen,      

 

The option key would be a nice touch although not necessary.   I've been using the scripts this morning successfully and they work well. 🙂

 

Thanks for explaining the language.   I partially recognised it but even pure JS isn't something I've spent much time with.   

If you want to make it official it might be worth adding a reference to iRacing and Trading Paints as this is the application/systems I'm using it for.   

 

Thanks again  Max

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 ,
Jun 19, 2024 Jun 19, 2024

Copy link to clipboard

Copied

I hate to revive a dead thread, but I found this script here:

Saving Targa Files for iRacing from Photoshop – Byte Insight

However, the script is saving to the D:\ drive? My documents folder is on the C:\ drive, how can I alter the script to be looking for the right folder on the right drive?

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 ,
Jun 19, 2024 Jun 19, 2024

Copy link to clipboard

Copied

LATEST
quote

I hate to revive a dead thread, but I found this script here:

Saving Targa Files for iRacing from Photoshop – Byte Insight

However, the script is saving to the D:\ drive? My documents folder is on the C:\ drive, how can I alter the script to be looking for the right folder on the right drive?


By @Kraig35611702ti38

 

Without testing, I would suggest that you change the following line from:

 

var thePath = "D:/Documents/iRacing/paint";

 

To the currently logged-in User's Documents folder:

 

var thePath = "~/Documents/iRacing/paint";

 

The code currently assumes that the iRacing/paint folders exist in the Documents folder. Extra code would be needed to create this directory structure if it didn't exist.

 

 

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