Skip to main content
Inspiring
December 16, 2022
Beantwortet

Get current Photoshop folder

  • December 16, 2022
  • 2 Antworten
  • 1396 Ansichten

Is there a way to get the current folder that is used by Photoshop via scripting? ie if you were to go to the save dialog - what folder would it show? $activePhotoshopFolder That one! (I made that up, BTW)

 

And secondly is possible to change it?

 

If you create a new document then try to assign a path (without saving it)

var srcDoc = app.activeDocument;
app.activeDocument.path = sourceFolder;
alert(app.activeDocument.path);

Error: 8103: The document has not been saved. Chicken meet Egg. Egg meet Chicken.

 

Why am I doing this? I want to change the folder path without having to pop up a dialog "Do you want to save the file?" at the end script and then saving to the new folder. - Does that make sense?

 

 

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

Photoshop keeps track of the folder you last saved a file to. That's what I'm after.


app.recentFiles

2 Antworten

Stephen Marsh
Community Expert
Community Expert
December 16, 2022

@Ghoul Fool – I have been known to set a path variable in a try/catch block:

 

try {
    // Use the previously saved path
    var docPath = activeDocument.path;
} catch (e) {
    // If unsaved, prompt for the save directory
    var docPath = Folder.selectDialog("Unsaved base file, select the output folder:");
}

 

The unsaved catch could be asking the user to select a folder, or a preset folder such as the ~/Desktop could be used if no interaction is required.

 

In the Save code which comes later, the docPath variable is then used, usually along with another variable for the docName which has had the existing filename extension removed so that a new hard-coded extension string can be added:

 

new File(docPath + "/" + docName + ".jpg"));

 

A working example here:

 

Inspiring
December 16, 2022

That's a nice work around and an example of answering the question in context.

But I asked can you get and/or set the current folder from Photoshop?

schroef
Inspiring
December 16, 2022

How can there be a current folder if nothing has been saved?!?!

There is no current folder, only when a document is open is there a path and that path is per open document.

 

Well actually there sort of is, that would be a tmp folder.

 

Inspiring
December 16, 2022

Sort of pre-empting the users desicions, but not forcing them.