Skip to main content
Liberty & Lace
Participating Frequently
December 6, 2024
Beantwortet

Action to use relative path of file

  • December 6, 2024
  • 3 Antworten
  • 1229 Ansichten

Is there any way I can set this sort of thing up in an action?

 

I curently use a simple generic action to flatten, save and close the file I am working on, an it simply overwrites the file in is current location. All good.

 

But not I want a similar Action to be able to save the same file (after resizing) file in a different folder, which will always be up one level, and I need trhis to work no matter what file for whatever client I am working on.

 

For instance, part of my base client folder structure is as follows:

 

c:\client name\Finished Files

c:\client name\Cropped Files

where "client name" is the name of the client

 

So when I have a file open in Finished Files, and I hit my curent action, it simple saves overt eh original file in the same place. But I would like to be able to save a rezed version in the other directory, which will always be there for all my client directory structures.

If I create an action to save in the Cropped Files directory, then the path the that clients Cropped Files will always be used. How can I make the action to work relative to the client directory structure?

 

Thank in advance

Dieses Thema wurde für Antworten geschlossen.
Beste Antwort von Stephen Marsh

@Liberty & Lace 

 

Try recording the execution of this script as the JPEG Save As (Copy) step in your action to save to the “Cropped” folder in the active client folder:

 

/*
JPEG Save As a Copy to Named Directory using Relative Path.jsx
Stephen Marsh
v1.0 - 7th December 2024
https://community.adobe.com/t5/photoshop-ecosystem-discussions/action-to-use-relative-path-of-file/td-p/15023267
*/

#target photoshop;

if (app.documents.length) {

    // Check and cancel the script if the bit depth is 32 bpc
    if (app.activeDocument.bitsPerChannel == BitsPerChannelType.THIRTYTWO) {
        throw alert("Script cancelled!\rThe image mode is 32 bpc, tone mapping to 8 or 16 bpc is required before continuing.");
    }

    // Doc name and save path variables
    var theDocName = app.activeDocument.name.replace(/\.[^\.]+$/, '');
    var relParentPath = app.activeDocument.path.parent.fsName;
    var targetDir = "Cropped"; // Change as required for other relative paths
    var relTargetDir = new Folder(relParentPath + "/" + targetDir);
    var theFilePath = new File(relTargetDir + "/" + theDocName + ".jpg");

    // Check for and create the target directory if it doesn't exist
    if (!relTargetDir.exists) {
        relTargetDir.create();
    }

    // JPEG options
    var jpgSaveOptions = new JPEGSaveOptions();
    jpgSaveOptions.embedColorProfile = true;
    jpgSaveOptions.formatOptions = FormatOptions.STANDARDBASELINE;
    jpgSaveOptions.matte = MatteType.NONE;
    jpgSaveOptions.quality = 12;

    // Overwrite check (comment out or remove this block for silent use in an action)
    if (theFilePath.exists) {
        // true = 'No' as default active button
        if (!confirm("File exists, overwrite: Yes or No?", true))
            // throw alert("Script cancelled!");
            throw null;
    }

    // Save As a Copy (use false for Save As)
    app.activeDocument.saveAs(theFilePath, jpgSaveOptions, true, Extension.LOWERCASE);

} else {
    alert("You must have a document open to use this script!");
}

 

https://prepression.blogspot.com/2017/11/downloading-and-installing-adobe-scripts.html

3 Antworten

Stephen Marsh
Community Expert
Community Expert
December 7, 2024

@Liberty & Lace 

 

Try recording the execution of this script as the JPEG Save As (Copy) step in your action to save to the “Cropped” folder in the active client folder:

 

/*
JPEG Save As a Copy to Named Directory using Relative Path.jsx
Stephen Marsh
v1.0 - 7th December 2024
https://community.adobe.com/t5/photoshop-ecosystem-discussions/action-to-use-relative-path-of-file/td-p/15023267
*/

#target photoshop;

if (app.documents.length) {

    // Check and cancel the script if the bit depth is 32 bpc
    if (app.activeDocument.bitsPerChannel == BitsPerChannelType.THIRTYTWO) {
        throw alert("Script cancelled!\rThe image mode is 32 bpc, tone mapping to 8 or 16 bpc is required before continuing.");
    }

    // Doc name and save path variables
    var theDocName = app.activeDocument.name.replace(/\.[^\.]+$/, '');
    var relParentPath = app.activeDocument.path.parent.fsName;
    var targetDir = "Cropped"; // Change as required for other relative paths
    var relTargetDir = new Folder(relParentPath + "/" + targetDir);
    var theFilePath = new File(relTargetDir + "/" + theDocName + ".jpg");

    // Check for and create the target directory if it doesn't exist
    if (!relTargetDir.exists) {
        relTargetDir.create();
    }

    // JPEG options
    var jpgSaveOptions = new JPEGSaveOptions();
    jpgSaveOptions.embedColorProfile = true;
    jpgSaveOptions.formatOptions = FormatOptions.STANDARDBASELINE;
    jpgSaveOptions.matte = MatteType.NONE;
    jpgSaveOptions.quality = 12;

    // Overwrite check (comment out or remove this block for silent use in an action)
    if (theFilePath.exists) {
        // true = 'No' as default active button
        if (!confirm("File exists, overwrite: Yes or No?", true))
            // throw alert("Script cancelled!");
            throw null;
    }

    // Save As a Copy (use false for Save As)
    app.activeDocument.saveAs(theFilePath, jpgSaveOptions, true, Extension.LOWERCASE);

} else {
    alert("You must have a document open to use this script!");
}

 

https://prepression.blogspot.com/2017/11/downloading-and-installing-adobe-scripts.html

Liberty & Lace
Participating Frequently
December 7, 2024

WOW! Thank you so much for doing that.

 

I certainly will give it a try, once I work out how 🙂

Stephen Marsh
Community Expert
Community Expert
December 7, 2024
quote

WOW! Thank you so much for doing that.

 

I certainly will give it a try, once I work out how 🙂


By @Liberty & Lace


You're welcome. Full instructions were posted in the link under the code.

D Fosse
Community Expert
Community Expert
December 6, 2024

-

Stephen Marsh
Community Expert
Community Expert
December 6, 2024

Actions always record absolute paths from the local machine recording the action.

 

You either override the recorded save when using Batch/Droplets – or you use a script instead, which can work with paths without the limitations of actions.

Liberty & Lace
Participating Frequently
December 6, 2024

Ok, great thanks.

I guessed it might need scripting, which can presumably be invoked by an action?

 

How do I go about creating scripts?

Stephen Marsh
Community Expert
Community Expert
December 6, 2024
quote

Ok, great thanks.

I guessed it might need scripting, which can presumably be invoked by an action?

 

How do I go about creating scripts?


By @Liberty & Lace

 

That's a bit of a loaded question.

 

Legacy scripting (what you mostly see on these forums) uses ExtendScript, however, there are less capable AppleScript and VB Script options.

 

Adobe have shifted to UXP scripting for the future, however, it isn't as accessible as I would like.

 

Can you post a screenshot of the file format options that you would use when saving, or a screenshot of an action step showing the file format options?