Skip to main content
Inspiring
February 23, 2025
Question

Save as script, File.save Dialog, default save location active document folder

  • February 23, 2025
  • 2 replies
  • 134 views

Trying to open  "File > Save  as" dialog from java script, with default open folder, active document folder, without success.  The dialog from script, always open last save location.

 

Any suggestions ?

Photoshop version 25.x

Preferences> File Handling  "Save as to Original folder " is ticked

( I have a script that saves at the desired location  without opening the save as dialog, but I need to browse folder contents before saving.)

2 replies

Stephen Marsh
Community Expert
Community Expert
February 23, 2025

@siomosp 

 

Here is an example using the standard file Save As dialog for JPEG.

 

/*
Default JPEG Save to Baseline Standard.jsx
https://community.adobe.com/t5/photoshop-ecosystem-discussions/save-as-jpeg-again/td-p/12650865
Stephen Marsh, 12th January 2022 - v1.0
Info: Uses the standard Photoshop interface with preset JPEG options
*/

#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:");
    }
    saveJPEG(10);
} else {
    alert("You must have a document open!");
}

function saveJPEG(compValue) {
    // Using the standard Photoshop dialog windows
	var ID = function (s) {
		return app.stringIDToTypeID(s);
	};
	var AD = new ActionDescriptor();
	AD.putInteger(ID("extendedQuality"), compValue);
	AD.putEnumerated(ID("matteColor"), ID("matteColor"), ID("none"));
	AD.putObject(ID("as"), ID("JPEG"), AD);
	AD.putPath(ID("in"), new File(docPath + "/" + docName + ".jpg"));
	executeAction(ID("save"), AD, DialogModes.ALL);
}

 

c.pfaffenbichler
Community Expert
Community Expert
February 23, 2025

@siomosp wrote:

( I have a script that saves at the desired location  without opening the save as dialog, but I need to browse folder contents before saving.)


Then I would recommend using a Folder-Selection-dialog instead of trying to use the Save As-dialog. 

This should present a dialog with the folder in which the active document resides, but you can naturally »hardcode« a location. 

 

var thedoc = app.activeDocument;
try {var docPath = thedoc.path}
catch (e) {var docPath = "~/Desktop"};
var theFolder = Folder(docPath).selectDlg ("select folder");
alert (theFolder);