• 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 PSD in subfolder of current folder

Community Beginner ,
Jan 08, 2023 Jan 08, 2023

Copy link to clipboard

Copied

I'm trying to script the following:

 

  1. Select the folder via a dialog box
  2. Only select PSD files in this folder
  3. Apply an action to the PSD files
  4. Save the files in a subfolder called "processed". This subfolder is in the same location as the PSD files themselves.

 

I copied the script provided to me for another issue. I can get the action to work, but even though I select an output folder, the files are still overwritten in the original location.

 

I have searched and tried all kinds of things but I can't get it to work. Here is the script that I have that succesfully overwrites the original files:

 

#target photoshop

// Disable dialog display
var restoreDialogMode = app.displayDialogs;
app.displayDialogs = DialogModes.NO;

(function () {

    // Select the input directory
    var inputFolder = Folder.selectDialog("Please select the input folder:");
    if (inputFolder === null) {
        // alert('Script cancelled!');
        return;
    }

    // Get the Photoshop files
    var fileList = inputFolder.getFiles(/\.psd$/i);

    // Validate that the file list is not empty
    var inputCount = fileList.length;
    var folderSelection = (inputCount === 0);
    if (folderSelection === true) {
        inputFolder = Folder.selectDialog("No files found, please reselect the input folder:");
        return;
    }

    // Select the output folder
    var outputFolder = Folder.selectDialog("Please select the output folder:");
    if (outputFolder === null) {
        // alert('Script cancelled!');
        return;
    }

    // Start the file count saving counter at zero
    var counter = 0;

    // Loop over the input files
    while (fileList.length) {
        for (var a = 0; a < 1; a++) {
            try {
                app.open(fileList.pop());
            } catch (e) {}
        }
        try {
			app.doAction('Profoto to sRGB','Profoto to sRGB.ATN');
			activeDocument.close(SaveOptions.SAVECHANGES);
	// Increment the file count saving counter
        counter++;
        } catch (error) {}
    }

    // End of script notification
    app.beep();
    alert('Script completed!' + '\r' + counter + ' files saved to:' + '\r' + outputFolder.fsName);

    // Restore the dialog display
    app.displayDialogs = restoreDialogMode;

}());

 

I reckon the issue is in the line activeDocument.close(SaveOptions.SAVECHANGES); This just does a save and overwrites the original file. I can't work out how to set it to a subfolder in the same directory. I tried to use activeDocument.saveAs but I can't get it to work.

 

Can anyone point me in the right direction?

TOPICS
Actions and scripting , Windows

Views

414

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 , Jan 08, 2023 Jan 08, 2023

I haven't tested the following, however, it should work as intended:

 

#target photoshop

// Disable dialog display
var restoreDialogMode = app.displayDialogs;
app.displayDialogs = DialogModes.NO;

(function () {

    // Select the input directory
    var inputFolder = Folder.selectDialog("Please select the input folder:");
    if (inputFolder === null) {
        // alert('Script cancelled!');
        return;
    }

    // Get the Photoshop files
    var fileList = inputFolder.getFiles(/\.psd$/i
...

Votes

Translate

Translate
Adobe
Community Expert ,
Jan 08, 2023 Jan 08, 2023

Copy link to clipboard

Copied

That code looks familiar!

 

In that topic, I forgot to remove the output folder selection from the copy from the original script. It wasn't required as the idea was to save the modified original over the top of itself. I'll fix that other code now...

 

I'll post back on this topic with the updated code that you need.

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 ,
Jan 08, 2023 Jan 08, 2023

Copy link to clipboard

Copied

LATEST

Haha indeed it was your code that you so kindly provided 🙂

I have tested the code you created for this particular request and it works perfectly. Again, thank you so much for your help!

 

Besides being able to bulk the profile conversion now, it's also very interesting to study the code of the script that you wrote. I'm learning a lot today 🙂

 

Thanks again!

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 ,
Jan 08, 2023 Jan 08, 2023

Copy link to clipboard

Copied

I haven't tested the following, however, it should work as intended:

 

#target photoshop

// Disable dialog display
var restoreDialogMode = app.displayDialogs;
app.displayDialogs = DialogModes.NO;

(function () {

    // Select the input directory
    var inputFolder = Folder.selectDialog("Please select the input folder:");
    if (inputFolder === null) {
        // alert('Script cancelled!');
        return;
    }

    // Get the Photoshop files
    var fileList = inputFolder.getFiles(/\.psd$/i);

    // Validate that the file list is not empty
    var inputCount = fileList.length;
    var folderSelection = (inputCount === 0);
    if (folderSelection === true) {
        inputFolder = Folder.selectDialog("No files found, please reselect the input folder:");
        return;
    }

    // Select the output folder
    var outputFolder = Folder.selectDialog("Please select the output folder:");
    if (outputFolder === null) {
        // alert('Script cancelled!');
        return;
    }

    // Start the file count saving counter at zero
    var counter = 0;

    // Loop over the input files
    while (fileList.length) {
        for (var a = 0; a < 1; a++) {
            try {
                app.open(fileList.pop());
            } catch (e) {}
        }
        try {
            app.doAction('Profoto to sRGB', 'Profoto to sRGB.ATN');
            saveOpenDocs();
            // Increment the file count saving counter
            counter++;
        } catch (error) {}
    }

    // End of script notification
    app.beep();
    alert('Script completed!' + '\r' + counter + ' files saved to:' + '\r' + outputFolder.fsName);

    // Restore the dialog display
    app.displayDialogs = restoreDialogMode;

    function saveOpenDocs() {
        var docName = app.activeDocument.name.replace(/\.[^\.]+$/, '');
        var saveFilePSD = new File(new File(outputFolder + '/' + docName + '.psd'));
        SavePSD(saveFilePSD);
        app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);

        // Setup PSD options
        function SavePSD(saveFilePSD) {
            psdSaveOptions = new PhotoshopSaveOptions();
            psdSaveOptions.embedColorProfile = true;
            psdSaveOptions.alphaChannels = true;
            psdSaveOptions.layers = true;
            psdSaveOptions.annotations = true;
            psdSaveOptions.spotColors = true;
            app.activeDocument.saveAs(saveFilePSD, psdSaveOptions, 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
Community Expert ,
Jan 08, 2023 Jan 08, 2023

Copy link to clipboard

Copied

To automatically create the save sub-folder without a dialog, change this:

 

    // Select the output folder
    var outputFolder = Folder.selectDialog("Please select the output folder:");
    if (outputFolder === null) {
        // alert('Script cancelled!');
        return;
    }

 

To this:

 

    // Set the output subfolder
    var outputFolder = new Folder(inputFolder + '/Profoto to sRGB/');
    if (!outputFolder.exists) {
        outputFolder.create();
    }

 

Again, the code is untested, but it should work as intended.

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