way to specify document name

Contributor ,
Apr 13, 2022 Apr 13, 2022

Copy link to clipboard

Copied

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

TOPICS
Scripting

Views

115

Likes

Translate

Translate

Report

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

correct answers 2 Correct answers

Participant , Apr 13, 2022 Apr 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];

Likes

Translate

Translate
Adobe Community Professional , Apr 13, 2022 Apr 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 );

Likes

Translate

Translate
Advisor ,
Apr 13, 2022 Apr 13, 2022

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

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
Participant ,
Apr 13, 2022 Apr 13, 2022

Copy link to clipboard

Copied

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];

 

Likes

Translate

Translate

Report

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 Professional ,
Apr 13, 2022 Apr 13, 2022

Copy link to clipboard

Copied

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 );

 

Likes

Translate

Translate

Report

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
Contributor ,
Apr 14, 2022 Apr 14, 2022

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

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 Professional ,
Apr 13, 2022 Apr 13, 2022

Copy link to clipboard

Copied

@GerssonDelgado 

😉

Two souls - one thought

Likes

Translate

Translate

Report

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 Professional ,
Apr 14, 2022 Apr 14, 2022

Copy link to clipboard

Copied

LATEST

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

 

Likes

Translate

Translate

Report

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