Skip to main content
Participant
December 29, 2016
Answered

How to open a dialog to pick a file or enter a filename?

  • December 29, 2016
  • 3 replies
  • 3419 views

Hi community,

I’m writing a script in JavaScript to process some images and save the result and some metadata in a folder and file chosen by the user.

Is there an API do that? i.e. to open a dialog similar to Photoshop’s save as dialog, so that the user can either pick a file already in the disk or enter the filename to create a new one.

I don’t want the dialog to save anything but just to return the full path to the file.

Best regards.

This topic has been closed for replies.
Correct answer pixxxelschubser

rraallvv77 schrieb:

… I don’t want the dialog to save anything but just to return the full path to the file.

Best regards.

I don't know what do you really want.

var aDoc = activeDocument;

var fName = aDoc.name;

alert(fName);

try {

    var fPath = aDoc.path;

    alert(fPath);

    }

catch (e) { alert(fName + " was never saved before") }

e.g. gives you the file name and the path (if your document has a file path - was saved)

File.saveDlg();

Gives you a dialog for saving.

What do you really want to do?

3 replies

hgfhtytr4Author
Participant
December 29, 2016

pixxxel schubser , I think saveDlg is the one I wanted thanks.

Jarda Bereza​, I already tried openDialog and searched in the photoshop-cc-javascript-ref-2015.pdf document but couldn't find anything similar to saveDlg, maybe the documentation is incomplete or I downloaded the wrong file, thanks.

pixxxelschubser
Community Expert
Community Expert
December 29, 2016

You're welcome.

Furthermore File.saveDialog() method also exists.

pixxxelschubser
Community Expert
pixxxelschubserCommunity ExpertCorrect answer
Community Expert
December 29, 2016

rraallvv77 schrieb:

… I don’t want the dialog to save anything but just to return the full path to the file.

Best regards.

I don't know what do you really want.

var aDoc = activeDocument;

var fName = aDoc.name;

alert(fName);

try {

    var fPath = aDoc.path;

    alert(fPath);

    }

catch (e) { alert(fName + " was never saved before") }

e.g. gives you the file name and the path (if your document has a file path - was saved)

File.saveDlg();

Gives you a dialog for saving.

What do you really want to do?

Jarda Bereza
Inspiring
December 29, 2016

From documentation:

Application.openDialog (): FileArray

Adobe Photoshop CC 2015.5 Object Library

Uses the Photoshop open dialog to select files.

Example:

alert(app.openDialog ());