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

How to write to a relative path with PS actions

New Here ,
May 30, 2022 May 30, 2022

Hi,

What is the way to do the above? PS always looks for an absolute path, therefore all my actions break.
Any easy fix?

Thanks

TOPICS
Actions and scripting , Windows
2.0K
Translate
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
Adobe
Community Expert ,
May 30, 2022 May 30, 2022

Are you familiar with JavaScript? 

Translate
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 ,
May 30, 2022 May 30, 2022

No but if there is an easy fix i ll take it

Translate
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 ,
May 30, 2022 May 30, 2022

I see no immediate, realistic option except Scripting and that is best done with JavaScript, but Visual Basic and AppleScript could also work. 

 

What is the exact relationship of the file’s position and the target location? 

What is the target file format? 

Translate
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 ,
May 30, 2022 May 30, 2022

AFAIK, you don't/can't do so with an action... Where are you using the absolute path in the action? In a save step, elsewhere?

 

You can turn on the modal control for an interactive override in the action.

 

Or you can use the "override action step" in Batch for recorded open or save commands.

 

Or you can use the "Insert menu item" command to place a generic open or save step into an action.

 

Otherwise, this is available via scripting, however it depends on the context of the step in the action on where/how you would use a scripted step recorded into the action.

Translate
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 ,
May 30, 2022 May 30, 2022

I only use it during save yes.
So whats the way of doing that without code (if possible)? thanks

Translate
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 ,
May 30, 2022 May 30, 2022

Will you please explain the exact scenario already? 

Save a Copy or Save As (or even Export …), file format, target position relative to original file, …? 

Translate
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 ,
May 30, 2022 May 30, 2022

I usually wanna do something like:
- open file
- Modify size
- Modify 16/8bit etc
- Close
and either
1. Save on the file that I am same format/same location or 2. Save as a different format/same location

Translate
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 ,
May 30, 2022 May 30, 2022

1. Save on the file that I am same format/same location 

So File > Save? That should not be a problem in an Action.  

 

Please try to describe what you are actually trying to automate that plain Actions cannot handle already. 

Translate
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 ,
May 30, 2022 May 30, 2022

This Script would save a jpg in the same Folder as the active Document (and if that has no path yet to the Desktop). 

Save the code as a txt-file, change the extension to .jsx and copy it into Photoshop’s Presets/Scripts-Folder; after restarting Photoshop it should be available under File > Scripts and can be assigned a Shortcut or used in an Action. 

// saves jpg into same folder;
// be advised: this  overwrites existing jpgs of the same name without prompting. 
// 2010, use it at your own risk;
#target photoshop;
if (app.documents.length > 0) {
var thedoc = app.activeDocument;
// getting the name and location;
var docName = thedoc.name;
if (docName.indexOf(".") != -1) {var basename = docName.match(/(.*)\.[^\.]+$/)[1]}
else {var basename = docName};
// getting the location, if unsaved save to desktop;
try {var docPath = thedoc.path}
catch (e) {var docPath = "~/Desktop"};
// jpg options;
var jpegOptions = new JPEGSaveOptions();
jpegOptions.quality = 9;
jpegOptions.embedColorProfile = true;
jpegOptions.matte = MatteType.NONE;
//save jpg as a copy:
thedoc.saveAs((new File(docPath+'/'+basename+'.jpg')),jpegOptions,true);
//that’s it; thanks to xbytor;
};

 

Translate
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 ,
May 30, 2022 May 30, 2022

Thanks so this is for writing specifically a jpeg?
It is not what I need though, I would need a script to just say "write whatever I define  in the relative path"

I would just need the "Save as" part but to a relative path. I use this for many different extensions. So i guess its not possible and requires different scripts each time?

Translate
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 ,
May 30, 2022 May 30, 2022

The Script is for jpg-creation. 

 

I don’t seem to understand what you are trying to automate. 

If you want to give manual input in the Save As-dialog anyway what is the problem to begin with? 

Maybe you could to explain the issue, possibly post meaningful screenshots or sketches to illustrate? 

Translate
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 ,
May 30, 2022 May 30, 2022

I understand that u dont understand. Since i never said i wanna save as JPEGs but u assumed it.
I said multiple times already the same thing with different wording:
I wanna save as various formats in their folder for whatever reason. My 2 previous posts were super descriptive. Doesnt need any further explanation. So its not possible to save relative paths.

Translate
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 ,
May 30, 2022 May 30, 2022

@thanulee wrote:

I understand that u dont understand. Since i never said i wanna save as JPEGs but u assumed it.


Is jpg not a file format and as such perfectly fitting as one of »various formats«? 

 


So its not possible to save relative paths.

Naturally it is possible to save copies (or a new file) to a position relative to the active document (edit: with Scripts).

As the example for jpg should have made clear. 

 


Doesnt need any further explanation. 

Not if you don’t actually want to automate the task, otherwise it does as far as I am concerened. 

What is »various formats« supposed to mean exactly? 

How is this supposed to happen in your workflow, do you expect a dialog or an instantaneous saving/exporting? 

Translate
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 ,
Oct 09, 2025 Oct 09, 2025
quoteI wanna save as various formats in their folder for whatever reason.

 

OK.

 

quote

So its not possible to save relative paths.


By @thanulee

 

With actions, not officially (but there is/used to be? a hack to record the save step in the action to a temporary volume/folder, which is then made unavailable, which forces the save as dialog to the current path).

 

With scripts, yes.

 

The following script offers an interactive save as dialog which defaults to the current open image directory:

 

/*
Default Save As to Source Directory.jsx
https://community.adobe.com/t5/photoshop-ecosystem-discussions/save-as-isn-t-saving-to-original-folder-even-after-resetting-default-preferences/m-p/13120058
Stephen Marsh, 7th August 2022 - v1.0
Info: Uses the standard Photoshop interface with the open file path
*/

#target photoshop

if (app.documents.length > 0) {
    var docName = app.activeDocument.name.replace(/\.[^\.]+$/, '');;
    try {
        // Use the previously saved path
        var docPath = app.activeDocument.path;
    } catch (e) {
        // If unsaved, prompt for save directory
        var docPath = Folder.selectDialog("Unsaved base file, select the output folder:");
    }
    saveFile();
} else {
    alert("You must have a document open!");
}

function saveFile() {
    // Using the standard Photoshop dialog window
	var ID = function (s) {
		return app.stringIDToTypeID(s);
	};
	var AD = new ActionDescriptor();
	AD.putPath(ID("in"), new File(docPath + "/" + docName));
	executeAction(ID("save"), AD, DialogModes.ALL);
}

  

Translate
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 ,
May 31, 2022 May 31, 2022

Please post a screenshot of the fully expanded Action in the Actions Panel and describe what you want it to achieve differently. 

Translate
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 ,
Oct 09, 2025 Oct 09, 2025

If you mean building an absolute path from a relative path, I can offer a method. You first need to build the relative paths relative to the very script you are gonna run with. Then do these: 

1. Use `$fileName` to get the full path with file name of the current script. We have a base now.

2. Use `new File($fileName)` or `File($fileName)` to get a file object, on which we can use `.parent` to get the absolute path.

3. Use ` '/' ` and `+` to connect the absolute path and your relative path. And use `new Folder` or `Folder` (if your relative path is a folder), or use `new File` or `File` (if you relative path contains the file name).

 

So it would look like this at last: `new File(new File($.fileName).parent +  relativePath (eg. '/../../Template/YourPSFile.psd') `. This gets you an absolute path at runtime, like you can use `app.open(new File(new File($.fileName).parent +  relativePath)` to open the file.

Translate
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
Advisor ,
Oct 09, 2025 Oct 09, 2025
LATEST

Yeah, that's not how it works.

If a document is open, we can get that path easily.

Keep in mind that this is a three year old post.

Translate
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