Skip to main content
Inspiring
April 13, 2022
Answered

way to specify document name

  • April 13, 2022
  • 5 replies
  • 650 views

Hi, when I create a new document via jsx script, it comes up as unnamed-1 or such.

I could of course pop up a save dialog suggesting a folder path and name, and I couuld perhaps add a save button to the script's UI if there is no better solution

Now, for a process where the lifetime of documents will usually be short, I would like to just preset a name and leave it to the user to actually save the file

This topic has been closed for replies.
Correct answer pixxxelschubser

The name can be added this way (but beware: the document itself is not yet saved this way)

 

var newDocPresets = new DocumentPreset;
newDocPresets.title = "Test-Document";

var newDoc = app.documents.addDocument( "Basic RGB", newDocPresets );

 

5 replies

pixxxelschubser
Community Expert
Community Expert
April 14, 2022

My snippet does what you asked. I am happy about that.

😉

The snippet from @GerssonDelgado is a bit more detailed and offers a few additional options. That's why I'm also marking his answer as correct. I hope that's okay with you.

 

For specific dimensions, the following properties can be used (in my snippet):

newDocPresets.width = 200; // in points
newDocPresets.height = 400; // in points

 

pixxxelschubser
Community Expert
Community Expert
April 13, 2022

@GerssonDelgado 

😉

Two souls - one thought

pixxxelschubser
Community Expert
pixxxelschubserCommunity ExpertCorrect answer
Community Expert
April 13, 2022

The name can be added this way (but beware: the document itself is not yet saved this way)

 

var newDocPresets = new DocumentPreset;
newDocPresets.title = "Test-Document";

var newDoc = app.documents.addDocument( "Basic RGB", newDocPresets );

 

Inspiring
April 14, 2022

Hi, many thanks, I will give it a try, but I will have to look up details, because I need RGB colorspace as well as a dimension determined by the script

GerssonDelgado
Inspiring
April 13, 2022

create new document with specific name:

var doc = app.activeDocument;
var namedoc=prompt("type a document name")
var presets = app.startupPresetsList;
var preset = presets[0];
var docPreset = new DocumentPreset();
docPreset.title = namedoc;
docPreset.rasterResolution = DocumentRasterResolution.HighResolution
docPreset.colorMode = DocumentColorSpace.CMYK;
docPreset.units = RulerUnits.Inches;
var doc = app.documents.addDocument(preset, docPreset, false);
doc.rulerOrigin = [0,0];

 

femkeblanco
Legend
April 13, 2022

A document's name is read-only.  The only way to change a document's name is through the file path when saving.