• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

[JS]: Is there anyway to change a document's name?

New Here ,
Jul 23, 2012 Jul 23, 2012

Copy link to clipboard

Copied

Is there anyway to change a document's name? Or create a document with a certain name?

I'm looking at the JavaScript reference, and it says that document.name is a readonly value. Is this entirely true / is there any other way to change the name of a document?

Any help would be much appreciated

Thanks!

TOPICS
Scripting

Views

4.1K

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 1 Correct answer

Community Expert , Jul 23, 2012 Jul 23, 2012

You can change the name of a document in two ways:

1. Open it, save it under a different name, and delete the original.

2. Don't open the document, use JavaScirpt's File object to rename the document. Details can be found in the JavaScript Tools Guide, accessed from your ESTK in the Help menu.

Peter

Votes

Translate

Translate
Advisor ,
Jul 23, 2012 Jul 23, 2012

Copy link to clipboard

Copied

app.documents.add ([showingWindow: bool=true][, documentPreset: DocumentPreset][, withProperties: Object])

the main interest for you is the "withProperties" part.


Votes

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
New Here ,
Jul 23, 2012 Jul 23, 2012

Copy link to clipboard

Copied

I'm new to javascript so bear with me :c

I don't fully understand the type Object. Since there is no specific reference for withProperties, I don't get how I would insert the parameters I need into a variable of the type "Object"

Is there somewhere I can see this?

Votes

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
Advisor ,
Jul 23, 2012 Jul 23, 2012

Copy link to clipboard

Copied

ok.. my mistake. i just tried it and it doesn't work.

Apparently the ony way to chage the name of the document is by saving it with (another) filename

var d=app.documents.add(false);

d.save("d:\mytestdoc.indd");

alert(d.name);

Votes

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
Community Expert ,
Jul 23, 2012 Jul 23, 2012

Copy link to clipboard

Copied

You can change the name of a document in two ways:

1. Open it, save it under a different name, and delete the original.

2. Don't open the document, use JavaScirpt's File object to rename the document. Details can be found in the JavaScript Tools Guide, accessed from your ESTK in the Help menu.

Peter

Votes

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 ,
Jul 23, 2012 Jul 23, 2012

Copy link to clipboard

Copied

LATEST

Hi Alex,

  Use this...

myDocument = app.activeDocument;

path = myDocument.fullName;

alert(path);

var x = path.toString().replace("oldName", "NewName");  

//OldName is ur file's name. newName is the name u want to save it.

myDocument.save(File(x));

With Regards,

Vel.

Votes

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