What's new
Photoshop Gurus Forum

Welcome to Photoshop Gurus forum. Register a free account today to become a member! It's completely free. Once signed in, you'll enjoy an ad-free experience and be able to participate on this site by adding your own topics and posts, as well as connect with other members through your own private inbox!

Action to save into current folder


Anthraquinone

New Member
Messages
4
Likes
1
There was a recent question "adjusting "save as" action" that is similar to mine but does not show me what I need to know.
I have an action to save an files as a png which works OK but what I really need is for it do save the image into the current folder, whatever that may be, not the one that was written into the action when I recorded it. Is this possible?.

Action.png
 
How about a script?

copy this script to your scripts folder (extension should be *.jsx)

If "saving as a PNG" is the only function you want to include in your action, you can also assign a shortcut to your script.

You can also integrate the script into your action.

JavaScript:
#target photoshop

(function () {
    if (app.documents.length === 0) {
        alert("No document open.");
        return;
    }

    var doc = app.activeDocument;

    // Derive file name and target path
    var nameNoExt = doc.name.replace(/\.[^\.]+$/, ""); // remove extension
    var extension = doc.name.split('.').pop().toLowerCase();
    if (extension === "png") {
        alert("This document is already a PNG. Saving would overwrite the original. Operation cancelled.");
        return;
    }

    var targetFolder = doc.fullName.parent;
    var targetFile = new File(targetFolder + "/" + nameNoExt + ".png");

    // Overwrite if it already exists
    if (targetFile.exists) {
        try {
            targetFile.remove();
        } catch (e) {
            alert("Failed to remove existing file:\n" + e);
            return;
        }
    }

    // PNG save options – moderate optimization (compression 6 of 0–9)
    var pngOpts = new PNGSaveOptions();
    pngOpts.compression = 6;          // 0 (none) … 9 (max) – 6 ≈ moderate
    pngOpts.interlaced  = false;      // no interlacing
    // Make sure profile is NOT embedded
    if (pngOpts.hasOwnProperty('embedColorProfile')) {
        pngOpts.embedColorProfile = false;
    }

    // Save with lower‑case extension
    doc.saveAs(targetFile, pngOpts, true /*asCopy*/, Extension.LOWERCASE);

    // Done
})();
 
Thank you for the reply. I have not used scripts before and did not think about doing it that way. Not surprisingly as I am not familiar with the script programming language. I will try you script and see if it works for me.

AQ
 


Write your reply...

Back
Top